I've read that LLVM can convert from C++ to C code. So I've used it in such a way: I'm Windows-user so I used MinGW. I employed this file as the test: llvm-hello.cpp: #include <iostream> int main(int argc, char* argv[]) { system("pause"); return 0; } result of "llvm-g++ C:\llvm_hello.cpp -o C:\llvm_hellopp.exe" worked just fine. as a result of "llvm-g++ -O3 -emit-llvm C:\llvm_hello.cpp -c -o C:\llvm_hellopp.bc" and "llc -march=c C:\llvm_hellopp.bc -o C:\llvm_helloCppToC.c" I obtained this charming stuff: http://codepaste.ru/2409/ And after "llvm-gcc C:\llvm_helloCppToC.c -o C:\llvm_helloCppToC.exe" I've got: "C:\llvm_helloCppToC.c: In function 'main': C:\llvm_helloCppToC.c:180: warning:return type of 'main' is not 'int' C:\...\Temp/ccfREe4x.o:fake:(.text+0xae): undefined reference to 'std::ios_base::Init::Init()' C:\...\Temp/ccfREe4x.o:fake:(.text+0xbe): undefined reference to 'std::ios_base::Init::~Init()' collect2: ld returned 1 exit status" What I've done wrong?
On Sep 29, 2009, at 9:37 AM, dilas dilas wrote:> I've read that LLVM can convert from C++ to C code.It does, but it does not supply a C++ library. You'll need to do that.> So I've used it in such a way: > I'm Windows-user so I used MinGW. > I employed this file as the test: > > llvm-hello.cpp: > > #include <iostream> > > int main(int argc, char* argv[]) > { > system("pause"); > return 0; > } > > result of "llvm-g++ C:\llvm_hello.cpp -o C:\llvm_hellopp.exe" worked > just fine. > > as a result of "llvm-g++ -O3 -emit-llvm C:\llvm_hello.cpp -c -o C: > \llvm_hellopp.bc" and > "llc -march=c C:\llvm_hellopp.bc -o C:\llvm_helloCppToC.c" I > obtained this charming stuff: > http://codepaste.ru/2409/ > And after "llvm-gcc C:\llvm_helloCppToC.c -o C:\llvm_helloCppToC.exe" > I've got: > "C:\llvm_helloCppToC.c: In function 'main': > C:\llvm_helloCppToC.c:180: warning:return type of 'main' is not 'int' > C:\...\Temp/ccfREe4x.o:fake:(.text+0xae): undefined reference to > 'std::ios_base::Init::Init()' > C:\...\Temp/ccfREe4x.o:fake:(.text+0xbe): undefined reference to > 'std::ios_base::Init::~Init()' > collect2: ld returned 1 exit status" > What I've done wrong? > > > > > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
> C:\...\Temp/ccfREe4x.o:fake:(.text+0xae): undefined reference to 'std::ios_base::Init::Init()' > C:\...\Temp/ccfREe4x.o:fake:(.text+0xbe): undefined reference to 'std::ios_base::Init::~Init()' > collect2: ld returned 1 exit status" > What I've done wrong?You need to link with C++ standard library. Either use llvm-g++ as linker, or add -lstdc++ -- With best regards, Anton Korobeynikov Faculty of Mathematics and Mechanics, Saint Petersburg State University
dilas dilas <espiritusantu at mail.ru> writes:> And after "llvm-gcc C:\llvm_helloCppToC.c -o C:\llvm_helloCppToC.exe"> C:\...\Temp/ccfREe4x.o:fake:(.text+0xae): undefined reference to 'std::ios_base::Init::Init()'You are not linking against your C++ standard library which contains the implementation of std::ios_base::Init. Try using g++ to link the file (it should link C++ libraries by default).
On Sep 29, 2009, at 9:48 AM, Dale Johannesen wrote:> > On Sep 29, 2009, at 9:37 AM, dilas dilas wrote: > >> I've read that LLVM can convert from C++ to C code. > > It does, but it does not supply a C++ library. You'll need to do > that.Right, also be aware of: http://llvm.org/docs/FAQ.html#translatecxx in particular, the caveats at the end. -Chris