Eli Friedman schrieb:> On Wed, Sep 17, 2008 at 3:39 PM, Michael Reichenbach > <michael_reichenbach at freenet.de> wrote: >> program.c will contain some non-human generated code. But it doesn't >> compile with gcc. There is an error, gcc complaints about undefined >> reference to std::cout and such (the code was just a very small example >> with cout). >> >> It hasn't be converted into "C only" code, can you tell me why? > > If your code uses the C++ library, you'll need to link it against a > C++ library. That has nothing to do with the language of the code. > > -EliI was only using the C++ standard lib. It doesn't need to be linked because it's only a header. Better said, it can't be linked with the std lib, never heard that it's needed to link it. Btw the code compiles and runs for sure with a g++ and also with llvm-g++. Only the converted C output contains still references to C++. How can I remove them? -mr
> I was only using the C++ standard lib. It doesn't need to be linked > because it's only a header. Better said, it can't be linked with the std > lib, never heard that it's needed to link it.Your program does need to have libstdc++ to linked it.> Btw the code compiles and runs for sure with a g++ and also with llvm-g++.Right, because they provide all needed extra magic libraries to linker. This will surely fail for you: g++ foo.cpp -o foo.o gcc foo.o> Only the converted C output contains still references to C++. How can I > remove them?You cannot, since you're compiling C++ sources and using C++ standard library. You've mentioned this explicitly before:> There is an error, gcc complaints about undefined > reference to std::cout and such (the code was just a very small > example with cout).Once again: you have C source code but with calls to C++ standard library (just as normal C calls). Thus you need to link libstdc++ in! -- With best regards, Anton Korobeynikov. Faculty of Mathematics & Mechanics, Saint Petersburg State University.
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. Regards, -mr