ld 找不到 `-lnsl`

ld cannot find `-lnsl`

我正在尝试编译一个 link 包含 nsl 库的项目,但它似乎无法 link 库:

/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 上 linked 但我是 运行 Arch Linux.

我有 2 个问题:

为什么 nsl 无法被 link 编辑,即使 λ 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 不要在不需要它的系统上 link nsl 的最纯粹的方法是什么?

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

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