gpt4 book ai didi

Clang 编译器忽略 .a 库文件

转载 作者:行者123 更新时间:2023-11-30 18:10:46 25 4
gpt4 key购买 nike

此编译有效确定:

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

这个(内部函数的 undefined reference ):

$ 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 模式生成的可执行文件时,程序会生成 «Shared object "libconfuse.so.2"not find, required by [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"

最佳答案

将命令行更改为:

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 直接链接到带有静态符号的二进制文件中。如果您遇到麻烦请告诉我

关于Clang 编译器忽略 .a 库文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55697036/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com