我试图编译一个链接nsl库的项目,但似乎无法链接库:
/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
我知道这个库不需要在MacOSX上链接,但我运行的是ArchLinux。
我有两个问题:
为什么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
的最纯粹的方法是什么? 最佳答案
问题在于-all-static
中的Makefile.am
选项。
ArchLinux不提供静态库(而debian当前的稳定版本提供了静态库)。