First of all, I am only doing something for fun, not for production.
LLVM's bitcode, to some extents, can works like Java's bytecode that can be cross platform. I think it should works in most situations, unless your code consists of some inline asm or something special. I have successfully compiled a simple hello world program with clang
to LLVM bitcode in Linux, and run it properly with lli
in Windows.
But, how can I use boost library such as boost_thread in that way? I can pack bitcode files together with llvm-link
, and it will still be cross platform. But if I link the bitcode with *.a by some methods (I have not tried to do that, but it seems that I can do so even llvm-ld
has been removed), it will probably not be cross platform anymore (and become a native binary executable file). So, I want to compile boost to LLVM bitcode, so that I can link the boost library to my program.
If you think that linking it statically will make the bitcode to large, you can also 'link' them in runtime, by lli <your bitcode> <boost's bitcode>...
I have compiled boost with ./b2 toolset=clang cxxflags="-emit-llvm -c"
. I am not sure whether I am in the right way. If not, is there any way for me to compile boost to bitcodes?
EDIT:
The above command seems to be partially work. The *.o files produced are LLVM bitcode, but it will then be archived to *.a. Simply decompress the *.a and use llvm-link
to link the files in the archive together may work.
BUT, unfortunately, there is inline asm in boost's thread library. So, it cannot run...