为什么不能找到libcurses.so,即使它位于`/ usr / lib`目录中?

时间:2017-07-28 02:54:18

标签: linux linker ld ncurses archlinux

Arch Linux上,当我构建某些内容时,ld抱怨无法找到curses库:

/usr/bin/ld: cannot find -lcurses
collect2: error: ld returned 1 exit status

但我的/usr/lib确实包含curses相关库:

# ls -lt /usr/lib/libcurse*
lrwxrwxrwx 1 root root 13 May 29 14:50 /usr/lib/libcurses.so -> libncurses.so
-rw-r--r-- 1 root root 18 May 29 14:50 /usr/lib/libcursesw.so
# ls -lt /usr/lib/libncurse*
-rw-r--r-- 1 root root     20 May 29 14:50 /usr/lib/libncurses++.so
lrwxrwxrwx 1 root root     18 May 29 14:50 /usr/lib/libncurses++w.so -> libncurses++w.so.6
lrwxrwxrwx 1 root root     20 May 29 14:50 /usr/lib/libncurses++w.so.6 -> libncurses++w.so.6.0
-rwxr-xr-x 1 root root  77264 May 29 14:50 /usr/lib/libncurses++w.so.6.0
-rw-r--r-- 1 root root     18 May 29 14:50 /usr/lib/libncurses.so
-rwxr-xr-x 1 root root 444776 May 29 14:50 /usr/lib/libncursesw.so.6.0
lrwxrwxrwx 1 root root     16 May 29 14:50 /usr/lib/libncursesw.so -> libncursesw.so.6
lrwxrwxrwx 1 root root     18 May 29 14:50 /usr/lib/libncursesw.so.6 -> libncursesw.so.6.0

我们可以看到libcurses.so指向libncurses.so,而libncurses.so是这样的:

# cat  /usr/lib/libncurses.so
INPUT(-lncursesw)

我尝试直接关联-lncursesw,但仍然存在链接错误:

/usr/bin/ld: cannot find -lncursesw
collect2: error: ld returned 1 exit status

为什么ld找不到libcurses.so,即使它位于/usr/lib目录中?

更新:

我正在构建bpftrace项目,链接错误如下:

[ 29%] Linking CXX executable bpftrace
cd /root/Project/bpftrace/build/src && /usr/bin/cmake -E cmake_link_script CMakeFiles/bpftrace.dir/link.txt --verbose=1
/usr/bin/c++  -g  -static -rdynamic CMakeFiles/bpftrace.dir/ast.cpp.o CMakeFiles/bpftrace.dir/attached_probe.cpp.o CMakeFiles/bpftrace.dir/bpftrace.cpp.o CMakeFiles/bpftrace.dir/codegen_llvm.cpp.o CMakeFiles/bpftrace.dir/driver.cpp.o CMakeFiles/bpftrace.dir/irbuilderbpf.cpp.o CMakeFiles/bpftrace.dir/main.cpp.o CMakeFiles/bpftrace.dir/map.cpp.o CMakeFiles/bpftrace.dir/mapkey.cpp.o CMakeFiles/bpftrace.dir/printer.cpp.o CMakeFiles/bpftrace.dir/printf.cpp.o CMakeFiles/bpftrace.dir/semantic_analyser.cpp.o CMakeFiles/bpftrace.dir/types.cpp.o  -o bpftrace arch/libarch.a ../libparser.a /usr/lib/libLLVMBPFCodeGen.a /usr/lib/libLLVMipo.a /usr/lib/libLLVMIRReader.a /usr/lib/libLLVMMCJIT.a ../bcc-prefix/src/bcc-build/src/cc/libbpf.a ../bcc-prefix/src/bcc-build/src/cc/libbcc-loader-static.a ../bcc-prefix/src/bcc-build/src/cc/libbcc.a -lelf /usr/lib/libLLVMAsmPrinter.a /usr/lib/libLLVMDebugInfoCodeView.a /usr/lib/libLLVMDebugInfoMSF.a /usr/lib/libLLVMBPFDesc.a /usr/lib/libLLVMBPFAsmPrinter.a /usr/lib/libLLVMBPFInfo.a /usr/lib/libLLVMSelectionDAG.a /usr/lib/libLLVMCodeGen.a /usr/lib/libLLVMAsmParser.a /usr/lib/libLLVMBitWriter.a /usr/lib/libLLVMInstrumentation.a /usr/lib/libLLVMLinker.a /usr/lib/libLLVMScalarOpts.a /usr/lib/libLLVMInstCombine.a /usr/lib/libLLVMVectorize.a /usr/lib/libLLVMTransformUtils.a /usr/lib/libLLVMExecutionEngine.a /usr/lib/libLLVMTarget.a /usr/lib/libLLVMAnalysis.a /usr/lib/libLLVMProfileData.a /usr/lib/libLLVMRuntimeDyld.a /usr/lib/libLLVMObject.a /usr/lib/libLLVMBitReader.a /usr/lib/libLLVMCore.a /usr/lib/libLLVMMCParser.a /usr/lib/libLLVMMC.a /usr/lib/libLLVMSupport.a -lrt -ldl -lcurses -lpthread -lz -lm /usr/lib/libLLVMDemangle.a
/usr/lib/libLLVMSupport.a(DynamicLibrary.cpp.o): In function `llvm::sys::DynamicLibrary::getPermanentLibrary(char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*)':
(.text._ZN4llvm3sys14DynamicLibrary19getPermanentLibraryEPKcPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0x6e): warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: cannot find -lcurses
collect2: error: ld returned 1 exit status

1 个答案:

答案 0 :(得分:1)

我想你的问题就在这里:

  

/ usr / bin / c ++ -g -static

你使用-static,这意味着:

  

在支持动态链接的系统上,这会阻止链接              共享库。在其他系统上,此选项无效。

所以对于成功的链接,你需要libcurses **。a **,而不是.so