[llvm-dev] Problem in taking llvm ir file via command line argument

David Wiberg via llvm-dev llvm-dev at lists.llvm.org
Sun Aug 12 05:26:04 PDT 2018


Hello,

Den sön 12 aug. 2018 kl 08:12 skrev Ratnesh Tiwari via llvm-dev
<llvm-dev at lists.llvm.org>:
>
> Hi, I am writing a program here hello.cpp for taking LLVM IR as a command line argument. My IR file is "input.bc" . But I dont understand how it make it via command line argument.
>
> I am running this hello.cpp as:
> g++ hello.cpp  -I /tmp/llvm/include/ -std=c++11 input.bc
>
> But it shows error. Please suggest me correct way of taking llvm ir file as CLA. Here, is mine program:
>
> ----------

When asking questions, please include any error messages you get as it
makes it easier for others to understand the problem.

The first problem I see is that you need to separate the steps
compiling "hello.cpp" and running the compiled file with "input.bc" as
input argument. The second problem is that you haven't specified any
libraries to link your source file to. In order to specify libraries
and compiler flags the tool llvm-config can be used. See example
below:
$ g++ -std=c++11 `llvm-config --cxxflags` hello.cpp -o hello
`llvm-config --ldflags --libs --system-libs`
$ echo 123 > input.bc
$ ./hello input.bc
Error reading bitcode: Corrupted bitcode

Best regards
David


More information about the llvm-dev mailing list