Search code examples
cllvmcheck-framework

How compile a llvm code file using functions from C?


Is there a way for compile a file in llvm (*.ll) that uses functions in C?

I created a test using check C and I compile it as:

$clang  counter_i.c counter_test_check.c   -lcheck

This way, I am using the libraries from check, but I need produce the llvm code that uses the library from check. When I try this command:

$clang -S -emit-llvm counter_i.c counter_test_check.c   

and try execute the code:

$lli-mp-3.5 counter_test_check.ll 

I receive this answer:

LLVM ERROR: Program used external function 'srunner_create' which could not be resolved!

I think that a solution is do something as:

$clang -S -emit-llvm counter_i.c counter_test_check.c   -lcheck

But it is not supported.

I am thinking that a similar answer is available at:LLVM JIT-compiled program cannot find external functions


Solution

  • I found a solution with:

    clang -S -emit-llvm -c counter_test_check.c counter_i.c  
    clang -o executable counter_test_check.ll counter_i.ll  -lcheck
    ./executable
    

    It does the compilation in two steps and this way I can use other llvm source file.