strophe / libstrophe

A simple, lightweight C library for writing XMPP clients
http://strophe.im/libstrophe
Other
401 stars 163 forks source link

/usr/bin/x86_64-w64-mingw32-ld: cannot find -lresolv #172

Closed peter279k closed 3 years ago

peter279k commented 3 years ago

When trying to cross compile from Linux to Windows with x86_64-w64-mingw32, it presents following configuring error:

/usr/bin/x86_64-w64-mingw32-ld: cannot find -lresolv

Reproducing issue

#!/bin/bash

sudo apt-get update
sudo apt-get install -y mingw-w64

export TOOLCHAIN=/usr
export CC=$TOOLCHAIN/bin/x86_64-w64-mingw32-gcc
export CXX=$TOOLCHAIN/bin/x86_64-w64-mingw32-g++
export AR=$TOOLCHAIN/bin/x86_64-w64-mingw32-ar
export LD=$TOOLCHAIN/bin/x86_64-w64-mingw32-ld
export RANLIB=$TOOLCHAIN/bin/x86_64-w64-mingw32-ranlib
export LDFLAGS="-L$(pwd)/../expat-2.2.10/_install/lib"
export LIBS="-lresolv"
export PKG_CONFIG_PATH="$(pwd)/../expat-2.2.10/_install/lib/pkgconfig"

if [[ ! -d "$(pwd)/_install" ]]; then
    mkdir "$(pwd)/_install"
fi;

./configure --host=x86_64-w64-mingw32 --prefix="$(pwd)/_install" --disable-shared --enable-static

make clean && make && make install

Can someone know about this issue? How to cross compile on Ubuntu for Windows?

peter279k commented 3 years ago

BTW, if removing the -lresolv (The $LIBS environment variable), it will present following configuring error:

configure: error: res_query() not found with LIBS="-lresolv"
pasis commented 3 years ago

I'm afraid there is no libresolv for mingw32. Correct me if I'm wrong. However, there is another option: c-ares. You can switch to c-ares with --enable-cares configure option.

There is a report that libstrophe can be built in your scenario: #159

peter279k commented 3 years ago

Hi @pasis, thanks for your reply.

After I use the --enable-cares when running ./configure script, it's worked.

I need to cross compile the ca-res project before crossing compiling the libstrophe project.

Finally, above of all crossing compilation have been done. And my ./build.sh script is as follows:

#!/bin/bash

# References: https://github.com/strophe/libstrophe/issues/159
# References: https://github.com/strophe/libstrophe/issues/172

export TOOLCHAIN=/usr
export CC=$TOOLCHAIN/bin/x86_64-w64-mingw32-gcc
export CXX=$TOOLCHAIN/bin/x86_64-w64-mingw32-g++
export AR=$TOOLCHAIN/bin/x86_64-w64-mingw32-ar
export LD=$TOOLCHAIN/bin/x86_64-w64-mingw32-ld
export RANLIB=$TOOLCHAIN/bin/x86_64-w64-mingw32-ranlib
export LDFLAGS="-L$(pwd)/../expat-2.2.10/_install/lib"
export CPPFLAGS="-I$(pwd)/../expat-2.2.10/_install/include"
export PKG_CONFIG_PATH=$(pwd)/../openssl-1.1.1i/_install/lib/pkgconfig
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:"$(pwd)/../c-ares-1.17.1/_install/lib/pkgconfig"

if [[ ! -d "$(pwd)/_install" ]]; then
    mkdir "$(pwd)/_install"
fi;

./configure --host=x86_64-w64-mingw32 --prefix="$(pwd)/_install" --enable-cares --disable-shared --enable-static

make clean && make && make install

Hopefully this building file can help others that want to cross compile libstrophe with x86_64-w64-mingw32 for Windows :).