使用llvm :: Function :: dump(),链接器给出“对`llvm :: Value :: dump()const的未定义引用". [英] Using llvm::Function::dump(), linker gives "undefined reference to `llvm::Value::dump() const'"

查看:552
本文介绍了使用llvm :: Function :: dump(),链接器给出“对`llvm :: Value :: dump()const的未定义引用".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试生成LLVM IR代码,作为万花筒教程的一部分,我已成功完成了该操作.

在同一台计算机上,使用这些相同的编译器标志.

I'm trying to generate LLVM IR code, which I have done successfully as part of the Kaleidoscope tutorial on this same machine, using these same compiler flags.

我的代码在clang ++ 3.4中编译时没有错误.但是,在链接时,我得到了:

My code compiles without errors in clang++ 3.4. However, at link time I'm getting:

undefined reference to `llvm::Value::dump() const'

该错误是由以下行触发的:

The error is being triggered by the line:

if (generator.code()) // returns llvm::Function*, or NULL
  generator.code()->dump();

如果我取消对dump()的呼叫,则链接器很高兴.

If I remove the call to dump(), the linker is happy.

我正在使用的Clang ++标志是:

Clang++ flags I'm using are:

-O3 -g -Wall -std=c++11 -I./src `llvm-config --cppflags --ldflags --libs core jit native`

我很困惑,因为万花筒项目可以编译并正常运行,并且使用相同的编译器标志并且在同一台计算机上构建.

I'm confused, because the Kaleidoscope project compiles and runs fine and uses the same compiler flags and is built on the same computer.

推荐答案

与库链接时,必须将库放置在源文件/目标文件后 .

When linking with libraries the libraries has to be placed after the source/object files.

所以您需要类似的东西

clang++ -O3 -g -Wall -std=c++11 -I./src \
    `llvm-config --cppflags --ldflags core jit native` \
    objectfile1.o objectfile2.o \
    `llvm-config --libs core jit native` \
    -o outputfile

这是因为链接器按照在命令行中给出的顺序查找符号.

It's because the linker looks for symbols in the order they are given on the command line.

这篇关于使用llvm :: Function :: dump(),链接器给出“对`llvm :: Value :: dump()const的未定义引用".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆