A question about 'llc -march=c'

Hello friends working on LLVM,
I am a beginner to LLVM. I tried to get C code from LLVM bitcode using
'llc -march=c'. But it seems to me that it doesn't work if the source
program is a C++ program. Am I right? I have attatched the source
program and the result of compiling the C code of it with GCC4.3.3.
By the way, has LLVM's C code backend been tested on benchmarks like
spec? Sorry if I missed the answers on websites.

Best regards,
Liang Peng

test.cc (157 Bytes)

gcc testcc.cbe.c.ouput (1.08 KB)

Hello

'llc -march=c'. But it seems to me that it doesn't work if the source
program is a C++ program. Am I right?

No. You haven't linked libstdc++ in your case. So, you either have to
provide -lstdc++ or link via g++.

lpeng <pengliang@ict.ac.cn> writes:

Hello friends working on LLVM,
I am a beginner to LLVM. I tried to get C code from LLVM bitcode using
'llc -march=c'. But it seems to me that it doesn't work if the source
program is a C++ program. Am I right?

If you use functions from some library on your C++ code (the C++
Standard Library, for example) calls to those functions are still
present on the generated C code. This means that you must provide the
referenced library on your compile command.

On your case, either compile with

gcc testcc.cbe.c -lstdc++

or with

g++ testcc.cbe.c

(g++ automatically adds the C++ standard library)

[snip]

Hi,
You need to link against the c++ standard library.
gcc test.cbe.c -lstdc++
works for me :slight_smile:
Cornelius

Thank you very much! It works now with -lstdc++.
And I still yearn to know whether LLVM's C code backend have been tested
on benchmarks like spec. :slight_smile:

Best regards
Liang Peng