[LLVMdev] converting C++ to C question
Luke Dalessandro
luked at cs.rochester.edu
Thu Sep 18 12:31:10 PDT 2008
Michael Reichenbach wrote:
> Please bare with me. :) Just to ensure I got nothing wrong.
>
> I can write in C++ + use C++ std lib + use other C++ libs and see if it
> compiles with a C++ compiler.
>
> After it's working I use llvm to do some magic and I get C code that I
> can compile with a standard C compiler on any platform? That's what I
> planed to do.
It's not the compiler that's causing the problem. All of the C++-isms
are getting converted into C, which you can then compile with a C
compiler. This includes things like new/delete, operator overloading, etc.
The problem is that you are using code found in the standard C++ library
which the linker can't find at link time. When you use the g++ driver to
do linking, it knows about the standard library and "does the right
thing" during linking. If you use the system linker you need to tell it
where to find the standard C++ library. You do this in LLVM by passing
-lstdc++ to llvm-ld during linking.
So the answer to your question is "yes" you can generate C code that
will compile on any platform, but in order to link it correctly you need
to link in the C++ library on that platform.
Hope this helps.
Luke
>
> Regards,
> -mr
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
More information about the llvm-dev
mailing list