alex
alex

Reputation: 23

Using LLVM headers when compiling LLVM IR

I am trying to compile C code fragment into LLVM IR. I need to #include the appropriate LLVM header files, e.g Module.h (#include "llvm/Module.h"). For compilation I use:

c++ -g prog.cpp llvm-config-10 --cxxflags --ldflags --libs core -o prog

But that gives me an error:

c++ -g prog.cpp llvm-config-10 --cxxflags --ldflags --libs core -o prog prog.cpp:1:10: fatal error: Module.h: No such file or directory

The output of llvm-config-10 --cxxflags is

-I/usr/lib/llvm-10/include ... etc

I have Module.h header in two locations:

/usr/include/llvm-10/llvm/IR/Module.h

and

/usr/lib/llvm-10/include/llvm/IR/Module.h

So, why does not "-I/usr/lib/llvm-10/include" work?

Shouldn't it find the header Module.h in .../llvm/IR directory?

Thanks in advance!

Upvotes: 1

Views: 802

Answers (1)

lxr196
lxr196

Reputation: 108

Instead of #include "llvm/Module.h put #include "llvm/IR/Module.h. Also, if you want to compile C code into LLVM IR, you can use the command clang -S -emit-llvm source.c, which will create a source.ll file containing the LLVM IR.

Upvotes: 1

Related Questions