ld找不到`-lnsl`

时间:2016-02-11 15:29:18

标签: linux build autoconf

我正在尝试编译链接 nsl lib的项目,但它似乎无法链接库:

/bin/sh ../../libtool  --tag=CXX   --mode=link g++  -DNDEBUG -std=c++11 -L/usr/lib -R/usr/lib  -L../../lib -all-static -lnsl  -o Client client.o nettools.o  -lgmm -lboost_program_options 
libtool: link: g++ -DNDEBUG -std=c++11 -static -o Client client.o nettools.o  -L/usr/lib -L../../lib -lnsl -lgmm -lboost_program_options -Wl,-rpath -Wl,/usr/lib
/bin/sh ../../libtool  --tag=CXX   --mode=link g++  -DNDEBUG -std=c++11 -L/usr/lib -R/usr/lib  -L../../lib -all-static -lnsl  -o Serveur serveur.o nettools.o  -lgmm -lboost_program_options 
/bin/ld: cannot find -lnsl
nettools.o: In function `creatSocketCom(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned int)':
nettools.cc:(.text+0x30e): warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
collect2: error: ld returned 1 exit status
Makefile:426: recipe for target 'Client' failed
make[2]: *** [Client] Error 1
make[2]: *** Waiting for unfinished jobs....
libtool: link: g++ -DNDEBUG -std=c++11 -static -o Serveur serveur.o nettools.o  -L/usr/lib -L../../lib -lnsl -lgmm -lboost_program_options -Wl,-rpath -Wl,/usr/lib
/bin/ld: cannot find -lnsl
nettools.o: In function `creatSocketCom(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned int)':
nettools.cc:(.text+0x30e): warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
collect2: error: ld returned 1 exit status

我知道这个库不需要在Mac OS X上链接,但是我正在运行Arch Linux。

我有 2 问题:

为什么 nsl 无法链接,即使λ ld --verbose -lnsl似乎显示在那里?

attempt to open /usr/x86_64-unknown-linux-gnu/lib64/libnsl.so failed
attempt to open /usr/x86_64-unknown-linux-gnu/lib64/libnsl.a failed
attempt to open /usr/lib/libnsl.so succeeded
-lnsl (/usr/lib/libnsl.so)
libc.so.6 needed by /usr/lib/libnsl.so
found libc.so.6 at /usr/lib/libc.so.6
ld-linux-x86-64.so.2 needed by /usr/lib/libc.so.6
found ld-linux-x86-64.so.2 at /usr/lib/ld-linux-x86-64.so.2
ld: warning: cannot find entry symbol _start; not setting start address

告诉autoconf不要在不需要它的系统上链接nsl的最纯粹方法是什么?

1 个答案:

答案 0 :(得分:0)

问题在于-all-static中的Makefile.am选项。

Arch Linux不提供静态库(而debian当前的稳定版本也是如此)。