Using llvm::Function::dump(), linker gives “undefined reference to `llvm::Value::dump() const'”

大城市里の小女人 提交于 2019-12-11 03:45:38

问题


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.

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();

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

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.


回答1:


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

So you need something like

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.



来源:https://stackoverflow.com/questions/22423120/using-llvmfunctiondump-linker-gives-undefined-reference-to-llvmvalue

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!