I have a C++ file, which hassome functions, such as:int myMax(int a,int b)
, and compile it to a llvm IR. Now I want to operate the IR in another C++ file, I don't know how to call the function(such as: myMax)in my C++ file.
Asked
Active
Viewed 841 times
1 Answers
0
You can compile IR to an object file for your platform (using llc
). This object file is like any other object file produced by, say, a C++ compiler. So you can call it from your C++ code.
More concretely. You compile a file with int myMax(int a, int b)
into some object file, say mymax.o
. Your "user" C++ code needs to:
- See the declaration of
myMax
by including the appropriate header, or just declaring the function prototype. - Link to
mymax.o
to have the implementation in the final executable.
Alternatively, you can use the existing JIT capability of LLVM to JIT the IR module in your C++ code and then use getPointerToFunction
to access it.

Eli Bendersky
- 263,248
- 89
- 350
- 412