linux - ld 找不到 `-lnsl`

标签 linux build autoconf

我正在尝试编译一个链接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

我知道这个库不需要在 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 的最纯粹的方法是什么?

最佳答案

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

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

关于linux - ld 找不到 `-lnsl`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35343418/

相关文章:

linux - smbclient锁的使用

c - 除了 system() 之外还有其他方法来执行二进制文件吗

docker - 如何在使用 Docker Compose 的同时高效地重建 go 项目?

cross-compiling - 告诉配置脚本使用 --datarootdir 的相对路径

linux - Unix sed XML 配置编辑

build - 如何在 intellij idea 中构建一个 java swing 应用程序

r - R中仅Unix的软件包错误

autotools - 如何获取autoconf configure.ac中顶级构建目录的绝对路径?

c++ - Makefile 应该在另一个目录中搜索 .o 文件