Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

convert C++ to C fails? linker problem? #890

Closed Quuxplusone closed 14 years ago

Quuxplusone commented 17 years ago
Bugzilla Link PR890
Status RESOLVED INVALID
Importance P normal
Reported by Mycroft Holmes (hp48gx@gmail.com)
Reported on 2006-08-29 09:49:06 -0700
Last modified on 2010-02-22 12:51:28 -0800
Version 1.8
Hardware Macintosh MacOS X
CC llvm-bugs@lists.llvm.org
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
Hi, I just installed LLVM1.8 with the shipped binaries of GCC4. To test the
installation I just entered
some simple commands manually at the terminal.
I'm not sure of what was wrong, maybe I made some wrong steps, but I think llc
is trying to make ld
link a c file against c++ libraries...

powerbookg4:/llvm/test mycroft$ cat hello.cpp
#include <iostream>

int main()
{
     std::cout << "hello world\n";
     return 0;
}
powerbookg4:/llvm/test mycroft$ ls -l
total 8
-rw-r--r--   1 mycroft  admin  95 Jan 12  2006 hello.cpp
powerbookg4:/llvm/test mycroft$ llvm-g++ hello.cpp
powerbookg4:/llvm/test mycroft$ ls -l
total 40
-rwxr-xr-x   1 mycroft  admin  14284 Aug 29 16:38 a.out
-rw-r--r--   1 mycroft  admin     95 Jan 12  2006 hello.cpp
powerbookg4:/llvm/test mycroft$ ./a.out
hello world
powerbookg4:/llvm/test mycroft$ llvm-g++ hello.cpp -c -emit-llvm -o hello.bc
powerbookg4:/llvm/test mycroft$ ls -l
total 48
-rwxr-xr-x   1 mycroft  admin  14284 Aug 29 16:38 a.out
-rw-r--r--   1 mycroft  admin   1948 Aug 29 16:38 hello.bc
-rw-r--r--   1 mycroft  admin     95 Jan 12  2006 hello.cpp
powerbookg4:/llvm/test mycroft$ lli hello.bc
hello world
powerbookg4:/llvm/test mycroft$ llc -march=c hello.bc -o hello.c
powerbookg4:/llvm/test mycroft$ ls -l
total 72
-rwxr-xr-x   1 mycroft  admin  14284 Aug 29 16:38 a.out
-rw-r--r--   1 mycroft  admin   1948 Aug 29 16:38 hello.bc
-rw-r--r--   1 mycroft  admin  11771 Aug 29 16:39 hello.c
-rw-r--r--   1 mycroft  admin     95 Jan 12  2006 hello.cpp
powerbookg4:/llvm/test mycroft$ cc hello.c
hello.c:221: warning: conflicting types for built-in function 'malloc'
/usr/bin/ld: Undefined symbols:
std::ios_base::Init::Init()
std::ios_base::Init::~Init()
std::cout
std::basic_ostream<char, std::char_traits<char> >& std::operator<<
<std::char_traits<char> >
(std::basic_ostream<char, std::char_traits<char> >&, char const*)
collect2: ld returned 1 exit status
Quuxplusone commented 17 years ago
The problem is that you're linking with "cc" which doesn't link in the c++
runtime library.  Try linking with
"llvm-g++ hello.c".

-Chris
Quuxplusone commented 17 years ago

Chris, shouldn't this be marked as resolved/invalid?

Quuxplusone commented 17 years ago

Sure.  Mycroft, if the solution doesn't work for you, please reopen.

-Chris

Quuxplusone commented 17 years ago

So the converted C file still needs the C++ library... I suggest to mention this explicitly in the FAQ

file:///llvm/vm/docs/llvm/html/FAQ.html#translatec++

I have a plain C compiler (and no C++ library).

Quuxplusone commented 17 years ago
I updated it with high-level instructions on how to use libstdc++ (or any other
c++ lib):
http://llvm.org/docs/FAQ.html#translatec++

Thanks,

-Chris