【问题标题】:Linker errors when using LLVM使用 LLVM 时的链接器错误
【发布时间】:2019-09-16 11:09:56
【问题描述】:

我正在尝试使用 LLVM 来构建编译器后端,但我陷入了链接器错误的泥潭。目前我试图做的只是包含 LLVMContext.h(我正在做 IBM tutorial),但这给了我以下链接器错误:

$ g++ -o compiler *.o -L/home/jakob/llvm2/lib/*.a -lantlr4-runtime
BayesBaseListener.o:(.data.rel+0x0): undefined reference to `llvm::DisableABIBreakingChecks'
collect2: error: ld returned 1 exit status
Makefile:2: recipe for target 'compiler' failed
make: *** [compiler] Error 1

知道如何正确配置 LLVM 以免发生这种情况吗?

【问题讨论】:

    标签: c++ compiler-construction llvm llvm-ir llvm-c++-api


    【解决方案1】:

    -L 选项是添加链接器用来搜索库的路径。选项-l(小写L)是告诉链接器链接到一个特定的库。

    不过,对于您的情况,如果您想链接特定位置的所有静态库,只需将库文件列为输入文件:

    g++ -o compiler *.o /home/jakob/llvm2/lib/*.a -lantlr4-runtime
    

    请注意,我不使用 -L 选项。

    【讨论】:

    • 好的,谢谢,但现在我收到了这个错误。 /usr/bin/ld: /home/jakob/llvm2/lib/libLLVMSupport.a(Error.cpp.o): 通用 ELF 中的重定位 (EM: 21) /home/jakob/llvm2/lib/libLLVMSupport.a: 错误添加符号:文件格式错误
    猜你喜欢
    • 2015-02-26
    • 1970-01-01
    • 2012-10-06
    • 1970-01-01
    • 1970-01-01
    • 2015-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多