-emit-llvm in Linux

冷暖自知 提交于 2019-12-05 05:48:21

Something is horrible broken in ubuntu packaging of llvm-gcc. llvm-gcc's version is 4.2.1, but here we're seeing 4.5. Please report Ubuntu bug.

bluesea

Try:

llvm-gcc -c -emit-llvm source.cpp

use -c instead of -S.

if it does not work, use:

clang -c -emit-llvm source.cpp

You can build llvm either from Ubuntu software center or download llvm-3.0-src and clang-src to compile them yourself.

From the LLVM tutorial:

$ llvm-gcc -O3 -emit-llvm hello.c -c -o hello.bc

Will compile the source hello.c into bytecode file hello.bc.

Then use the llvm-dis utility to take a look at the LLVM assembly code:

$ llvm-dis < hello.bc | less

If you want to play with LLVM, build it from source: http://clang.llvm.org/get_started.html

Otherwise, to quick start, try to install clang on Ubuntu. This is the C/C++ compiler built on top of LLVM. You will be able to generate LLVM IR from clang directly.

llvm-gcc seems to be based on dragon-egg, which is no longer supported in LLVM AFAIK.

drunk teapot

Do the steps on http://clang.llvm.org/get_started.html this will install llvm and clang from svn. So you'll build from source

but with minor difference: ../llvm/configure --prefix=/usr/local --enable-optimized make -j4 make install (to install tools under /usr/local)

(install release+asserts instead of debug+asserts or go with ../llvm/configure for debug+asserts I have an i5 so I used make -j4 change as you wish)

use clang not llvm-gcc. You can then directly generate an .ll by: clang -S -emit-llvm file.cpp -o file.ll

and clang -c -emit-llvm file.cpp -o file.bc

if you like to get and .s do the following: llc file.bc

this is the cleanest way for the latest version of llvm on ubuntu


Same thing happens with llvm-gcc-4.6 which is also dragonEgg version I suppose.

I'm getting llvm-gcc potential incompatible plug-in version

After this point I get exactly the same error with llvm-dis:

"llvm-dis: Invalid bitcode signature".

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!