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

StackOverflow https://stackoverflow.com/questions/22423120

  •  15-06-2023
  •  | 
  •  

Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top