Clang编译器忽略.a库文件

问题描述 投票:0回答:2

这个编译工作正常:

$ clang -target x86_64-unknown-freebsd10.0 --sysroot=/opt/cross-freebsd-10/ -l:libconfuse.so main.cpp

这个没有(内部函数的未定义引用):

$ clang -target x86_64-unknown-freebsd10.0 --sysroot=/opt/cross-freebsd-10/ -l:libconfuse.a main.cpp
/tmp/main-115bc4.o: En la función `main':
main.cpp:(.text+0x691): referencia a `cfg_init' sin definir
main.cpp:(.text+0x6ab): referencia a `cfg_parse' sin definir
main.cpp:(.text+0x6da): referencia a `cfg_getstr' sin definir
clang: error: linker command failed with exit code 1 (use -v to see invocation)

与这些命令行相同的错误:

$ clang -target x86_64-unknown-freebsd10.0 --sysroot=/opt/cross-freebsd-10/ -L/opt/cross-freebsd-10/usr/lib/ -l:libconfuse.a main.cpp
$ clang -target x86_64-unknown-freebsd10.0 --sysroot=/opt/cross-freebsd-10/ -L/opt/cross-freebsd-10/usr/lib/ -l:libconfuse.a -static main.cpp

LibConfuse C编程库的文件似乎位于正确的路径:

$ ls -la /opt/cross-freebsd-10/usr/lib/libconfuse*
-rwxrwxrwx 1 luis luis 78318 sep 29  2018 /opt/cross-freebsd-10/usr/lib/libconfuse.a
lrwxrwxrwx 1 luis luis    19 sep 29  2018 /opt/cross-freebsd-10/usr/lib/libconfuse.so -> libconfuse.so.2.0.0
lrwxrwxrwx 1 luis luis    19 sep 29  2018 /opt/cross-freebsd-10/usr/lib/libconfuse.so.2 -> libconfuse.so.2.0.0
-rwxr-xr-x 1 luis luis 56616 sep 29  2018 /opt/cross-freebsd-10/usr/lib/libconfuse.so.2.0.0

所以,我会说编译器无法看到.a文件。我对吗?我该怎么解决?

我需要解决这个问题,因为我试图使用LibConfuse库的静态链接进行编译,只要我不需要在目标计算机上安装该包。因此,正如我所读到的,必须使用.a库文件。

进一步数据:

  • 请注意,我正在交叉编译FreeBSD。我不知道这是否重要。
  • 当运行(在远程FreeBSD计算机上)上面的.so模式生成的可执行文件时,程序会生成“共享对象”libconfuse.so.2“找不到,[MyExecutableName]”需要。这就是我尝试执行静态链接的原因。
  • 在Ubuntu Linux v16.04上进行的测试。

请求时的新数据:

相同的第一行工作正常,但使用-###参数显示额外信息:

1$ clang -### -target x86_64-unknown-freebsd10.0 --sysroot=/opt/cross-freebsd-10/ -l:libconfuse.so main.cpp
clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final)
Target: x86_64-unknown-freebsd10.0
Thread model: posix
InstalledDir: /usr/bin
 "/usr/lib/llvm-3.8/bin/clang" "-cc1" "-triple" "x86_64-unknown-freebsd10.0" "-emit-obj" "-mrelax-all" "-disable-free" "-disable-llvm-verifier" "-main-file-name" "main.cpp" "-mrelocation-model" "static" "-mthread-model" "posix" "-mdisable-fp-elim" "-masm-verbose" "-mconstructor-aliases" "-munwind-tables" "-target-cpu" "x86-64" "-dwarf-column-info" "-debugger-tuning=gdb" "-resource-dir" "/usr/lib/llvm-3.8/bin/../lib/clang/3.8.0" "-isysroot" "/opt/cross-freebsd-10/" "-internal-isystem" "/opt/cross-freebsd-10//usr/include/c++/v1" "-fdeprecated-macro" "-fdebug-compilation-dir" "/media/Almacen01/Temporal/CPlusPlus/PruebaCSV01" "-ferror-limit" "19" "-fmessage-length" "83" "-fobjc-runtime=gnustep" "-fcxx-exceptions" "-fexceptions" "-fdiagnostics-show-option" "-fcolor-diagnostics" "-o" "/tmp/main-065e9b.o" "-x" "c++" "main.cpp"
 "/usr/bin/ld" "--sysroot=/opt/cross-freebsd-10/" "--eh-frame-hdr" "-dynamic-linker" "/libexec/ld-elf.so.1" "--hash-style=both" "--enable-new-dtags" "-o" "a.out" "/opt/cross-freebsd-10//usr/lib/crt1.o" "/opt/cross-freebsd-10//usr/lib/crti.o" "/opt/cross-freebsd-10//usr/lib/crtbegin.o" "-L/opt/cross-freebsd-10//usr/lib" "-l:libconfuse.so" "/tmp/main-065e9b.o" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "/opt/cross-freebsd-10//usr/lib/crtend.o" "/opt/cross-freebsd-10//usr/lib/crtn.o"

艾哈迈德要求提供更多数据:

$ clang -### -target x86_64-unknown-freebsd10.0 --sysroot=/opt/cross-freebsd-10/ /opt/cross-freebsd-10/usr/lib/libconfuse.a main.o -o LogManager
clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final)
Target: x86_64-unknown-freebsd10.0
Thread model: posix
InstalledDir: /usr/bin
 "/usr/bin/ld" "--sysroot=/opt/cross-freebsd-10/" "--eh-frame-hdr" "-dynamic-linker" "/libexec/ld-elf.so.1" "--hash-style=both" "--enable-new-dtags" "-o" "LogManager" "/opt/cross-freebsd-10//usr/lib/crt1.o" "/opt/cross-freebsd-10//usr/lib/crti.o" "/opt/cross-freebsd-10//usr/lib/crtbegin.o" "-L/opt/cross-freebsd-10//usr/lib" "/opt/cross-freebsd-10/usr/lib/libconfuse.a" "main.o" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "/opt/cross-freebsd-10//usr/lib/crtend.o" "/opt/cross-freebsd-10//usr/lib/crtn.o"
c static-linking
2个回答
0
投票

将命令行更改为:

clang -target x86_64-unknown-freebsd10.0 --sysroot=/opt/cross-freebsd-10/ -c main.cpp -o main.o 
clang -target x86_64-unknown-freebsd10.0 --sysroot=/opt/cross-freebsd-10/  /opt/cross-freebsd-10/usr/lib/libconfuse.a main.o -o main

这将允许您使用静态符号将libconfuse.a权限链接到二进制文件。如果你遇到麻烦,请告诉我


-1
投票

如果你想链接到库文件libconfuse.a然后你可以通过只指定文件名(没有-l:part)来做,或者你可以写-lconfuse(然后假设lib和.a部分。编写-l:libconfuse.a将不起作用, 我认为。

© www.soinside.com 2019 - 2024. All rights reserved.