compile .bc in cpp program

Hello, can i compile binary file .bc in my cpp program? now i use following code:

if (system(“opt a.out.bc -std-compile-opts -disable-inlining -loop-deletion -loop-extract -loop-extract-single -loop-rotate -loop-index-split -loop-unroll -opt-phis -loop-unswitch -loop-reduce -o test.bc”) == -1) {
Error(“Don’t install LLVM!”);


if (system(“llvmc test.bc -o test.out”) != -1) {…}
if (system(“ldd test.out”) == -1) {…}

and what keys using in clang with flag -O3?
With respect Andrei.

Hi Андрей Кабылин,

the tools directory contains a bunch of cpp programs that load, optimize and
codegen bitcode (eg: opt and llc). They are quite small since all the real
work is done in the LLVM libraries. I suggest you copy what they do.

Ciao, Duncan.