Clang 链接器问题(从源代码到 gcc-snapshot)

标签 clang ubuntu-12.04 dynamic-linking

我似乎无法让它发挥作用。我配置了--with-gcc-toolchain=在等号之后,我放置了 gcc 所在的目录( /usr/lib/gcc-snapshot/bin )。

我还查看了“clang linker problem”的答案,但我看不到如何获得接受的答案以找到正确的位置,并且符号链接(symbolic link)答案会起作用,除了它正在搜索的所有目录都存在(将 lib 文件夹从 gcc-snapshot 复制到包含位置之一似乎没有帮助)。

正如另一个问题中所建议的,clang++ test.cpp -v 的输出:

bob@bob:~/programming$ clang++ test.cpp -v
clang version 3.3 (trunk 171350)
Target: x86_64-unknown-linux-gnu
Thread model: posix
"/home/bob/programming/build/Release+Asserts/bin/clang" -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -main-file-name test.cpp -mrelocation-model static -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -target-linker-version 2.22 -momit-leaf-frame-pointer -v -resource-dir /home/bob/programming/build/Release+Asserts/bin/../lib/clang/3.3 -fmodule-cache-path /var/tmp/clang-module-cache -internal-isystem /usr/local/include -internal-isystem /home/bob/programming/build/Release+Asserts/bin/../lib/clang/3.3/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -fdebug-compilation-dir /home/bob/programming -ferror-limit 19 -fmessage-length 80 -mstackrealign -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -backend-option -vectorize-loops -o /tmp/test-PWiB4M.o -x c++ test.cpp
clang -cc1 version 3.3 based upon LLVM 3.3svn default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/home/bob/programming/build/Release+Asserts/bin/../lib/clang/3.3/include
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
test.cpp:1:10: fatal error: 'iostream' file not found
#include ^
1 error generated.



clang 3.3 版(主干修订版 171350)

编辑:没有.o Release+Asserts 中的文件用于构建的文件夹。这是正常的吗?如果不是,为什么会这样,我该如何修复它(如果我可以将它作为 clang 的 stdlib,那么它也可以)。

编辑 2:它也无法编译int main(){return 0;}因为找不到crtbegin.o .完整输出如下:

/usr/bin/ld: cannot find crtbegin.o: No such file or directory
/usr/bin/ld: cannot find -lgcc
/usr/bin/ld: cannot find -lgcc_s
clang: error: linker command failed with exit code 1 (use -v to see invocation)


-v 之后的结果与上述相同,但结束错误不同。

配置日志:
完整的文件可以找到here ,但第一行(非注释)是:$ ../llvm/configure --with-gcc-toolchain=/usr/lib/gcc-snapshot/gcc

最佳答案

我们发现的问题是 gcc 是使用 --prefix=/usr/lib/gcc-snapshot 配置参数安装的。并且 llvm 配置了 --with-gcc-toolchain=/usr/lib/gcc-snapshot/gcc 参数。它应该与 gcc 安装前缀相同,即 --with-gcc-toolchain=/usr/lib/gcc-snapshot。

问题的当前第一行显示“我使用 --with-gcc-toolchain= 进行了配置,在等号之后我放置了 gcc 所在的目录 (/usr/lib/gcc-snapshot/bin)。”,以及当前的最后一行说“第一(非注释)行是:$ ../llvm/configure --with-gcc-toolchain=/usr/lib/gcc-snapshot/gcc”

这很令人费解,你可能认为你放了标志 --with-gcc-toolchain=/usr/lib/gcc-snapshot/bin 但你实际上放了 --with-gcc-toolchain=/usr/lib/gcc -快照/gcc

无论如何,我认为您应该尝试以下方法。

  • 删除或重命名构建目录(运行配置命令的目录,即找到 config.log 文件的目录)我假设它是/home/bob/programming/build 目录。
  • 现在再次创建/home/bob/programming/build 目录。它现在应该是空的。
  • cd/home/bob/programming/build
  • 运行以下配置命令
    ../llvm/configure --with-gcc-toolchain=/usr/lib/gcc-snapshot
  • 完成其余的构建过程。

  • 问题似乎是您没有正确指定 gcc-toolchain 前缀。它应该与您在配置 gcc 时使用的 --prefix 参数相同。

    在这里报告结果。

    另见 Clang 3.2 build broken after building gcc 4.7

    关于Clang 链接器问题(从源代码到 gcc-snapshot),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14118224/

    相关文章:

    c++ - 在没有 root 权限的情况下使用 UDP 套接字

    c++ - 共享库的生命周期?

    c++ - 为什么 Clang 不附带标准库头文件?

    javascript - Clang 是否为 WebAssembly 的 memory.fill 和 memory.copy 提供内在函数?

    Clang 用户文档

    c - -rdynamic 仅用于选择符号?

    c++ - GLIBC_2.18 未找到,但在本地构建中

    c++ - 为 libclang 全局设置 -D 宏编译器标志

    Tomcat 7 中的 Eclipse 4.2 (Juno) 'Cannot create a server using the selected type'

    ubuntu-12.04 - 如何在 Ubuntu 12.04 上安装 qt quick 2?