Siarshai / llvm4eclipsecdt

Automatically exported from code.google.com/p/llvm4eclipsecdt
0 stars 0 forks source link

Cannot compile 'Hello World' C++ project on Fedora 15 #47

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
When i try to compile "Hello World" project on fedora 15, i've got several 
errors.

$ cat essai-clang.cpp 
//============================================================================
// Name        : essai-clang.cpp
// Author      : sca
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main()
{
    cout << "Hello World" << endl; // prints Hello World
    return 0;
}

Build console :
**** Build of configuration Debug for project essai-clang ****

**** Internal Builder is used for build               ****
clang++ -O0 -emit-llvm -g3 -Wall -c -fmessage-length=0 -osrc/essai-clang.bc 
../src/essai-clang.cpp
llvm-ld -v -native -o essai-clang src/essai-clang.bc
  Linking bitcode file 'src/essai-clang.bc'
  Linked in file 'src/essai-clang.bc'
Generating Bitcode To essai-clang.bc
Generating Assembly With: 
'/usr/local/bin/llc' '-x86-asm-syntax=att' '-o' 'essai-clang.s' 
'essai-clang.bc' 
Generating Native Executable With:
'/usr/bin/gcc' '-fno-strict-aliasing' '-O3' '-o' 'essai-clang' 'essai-clang.s' 
/tmp/ccK3UIL2.o: In function `main':
/home/ste/workspace/essai-clang/Debug/../src/essai-clang.cpp:14: undefined 
reference to `std::cout'
/home/ste/workspace/essai-clang/Debug/../src/essai-clang.cpp:14: undefined 
reference to `std::basic_ostream<char, std::char_traits<char> >& 
std::operator<< <std::char_traits<char> >(std::basic_ostream<char, 
std::char_traits<char> >&, char const*)'
/home/ste/workspace/essai-clang/Debug/../src/essai-clang.cpp:14: undefined 
reference to `std::basic_ostream<char, std::char_traits<char> >& 
std::endl<char, std::char_traits<char> >(std::basic_ostream<char, 
std::char_traits<char> >&)'
/home/ste/workspace/essai-clang/Debug/../src/essai-clang.cpp:14: undefined 
reference to `std::basic_ostream<char, std::char_traits<char> 
>::operator<<(std::basic_ostream<char, std::char_traits<char> >& 
(*)(std::basic_ostream<char, std::char_traits<char> >&))'
/tmp/ccK3UIL2.o: In function `global constructors keyed to a':
/home/ste/workspace/essai-clang/Debug/../src/essai-clang.cpp:15: undefined 
reference to `std::ios_base::Init::Init()'
/home/ste/workspace/essai-clang/Debug/../src/essai-clang.cpp:15: undefined 
reference to `std::ios_base::Init::~Init()'
collect2: ld a retourné 1 code d'état d'exécution
llvm-ld: 
Build error occurred, build is stopped
Time consumed: 4119  ms.  

If i replace the line :
'/usr/bin/gcc' '-fno-strict-aliasing' '-O3' '-o' 'essai-clang' 'essai-clang.s'

by :
'/usr/bin/g++' '-fno-strict-aliasing' '-O3' '-o' 'essai-clang' 'essai-clang.s'

everything works ok.

Original issue reported on code.google.com by stephane...@gmail.com on 1 Aug 2011 at 10:15

GoogleCodeExporter commented 9 years ago
This is a good find. The reason for this behavior is probably that the plug-in 
is unable to find the standard c++ library (thus undefined references). The 
current way of obtaining the c++ libraries is far from optimal. However your 
suggestion seems to work for you and therefore might work universally for other 
operating systems as well.

May I ask how did you manage to change '/usr/bin/gcc' to '/usr/bin/g++'?

Original comment by petri.tuononen@gmail.com on 8 Sep 2011 at 6:05

GoogleCodeExporter commented 9 years ago
Simple, i didn't manage to ;) !
I just copy and paste this line into my terminal, replacing gcc by g++, to
follow an advice on compiling c++ with g++ not gcc.
(sorry if this explanation is not clear, english is not my natural
language).

Original comment by stephane...@gmail.com on 9 Sep 2011 at 7:18

GoogleCodeExporter commented 9 years ago
Ok, thanks for clarification :)
I try to figure out why it tries to use gcc with C++ projects instead of g++.

Original comment by petri.tuononen@gmail.com on 9 Sep 2011 at 2:24

GoogleCodeExporter commented 9 years ago
System compiler /usr/bin/gcc is automatically called after LLVM's Linker 
(llvm-ld) therefore I did not find a way to modify it in plug-in.

The only solution I can give is to define -l and -L flags to LLVM's linker.
1) Open up a terminal on Linux and execute command: locate libstdc++.a
2) Copy and paste the path without file name inside Eclipse into Window -> 
Preferences -> LLVM -> Library search path directories
3) Check that libraries have stdc++ if not add it.

Hope this helps.

Original comment by petri.tuononen@gmail.com on 10 Sep 2011 at 2:31

GoogleCodeExporter commented 9 years ago
Thanks, i will try this workaround soon.
To make it clear, is it a problem in llvm-ld, in eclipse or into the plugin
infrastructure ?

Original comment by stephane...@gmail.com on 11 Sep 2011 at 7:39

GoogleCodeExporter commented 9 years ago
Well I am not totally sure yet. It seems like llvm-ld defaults to /usr/bin/gcc 
as a post compilation procedure so that I believe there is not much I can do 
plug-in wise.

Original comment by petri.tuononen@gmail.com on 11 Sep 2011 at 8:40

GoogleCodeExporter commented 9 years ago
Thanks...this really helped. I could not see the mistake. Well done!!

Original comment by tariqsu...@gmail.com on 22 Mar 2014 at 10:05