【问题标题】:ld cannot find `-lnsl`ld 找不到`-lnsl`
【发布时间】:2016-02-11 15:29:17
【问题描述】:

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

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

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 的最纯粹的方法是什么?

【问题讨论】:

    标签: linux build autoconf


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-07
      • 2021-12-21
      • 2015-01-30
      • 2018-06-15
      • 2012-10-24
      • 2015-06-19
      • 2014-12-13
      • 1970-01-01
      相关资源
      最近更新 更多