| View previous topic :: View next topic |
| Author |
Message |
MaRTiaN Tux's lil' helper

Joined: 22 Apr 2002 Posts: 85 Location: London
|
Posted: Wed May 28, 2003 5:38 pm Post subject: Problems with gcc & g++ |
|
|
I've seen a solution to this ages ago, but for all the searching I've done I couldn't find it so here goes.
1. g++ only works as root. If I try to compile a C++ program with another user I get -bash: world.cpp: command not found. (world.cpp is the generic hello world program I'm using to test this with.)
2. gcc world.cpp gives me loads of errors (for any user)
| Code: | In file included from /usr/lib/gcc-lib/i686-pc-linux-gnu/3.2.2/include/g++-v3/ba
ckward/iostream.h:31,
from world.cpp:1:
/usr/lib/gcc-lib/i686-pc-linux-gnu/3.2.2/include/g++-v3/backward/backward_warnin
g.h:32:2: warning: #warning This file includes at least one deprecated or antiqu
ated header. Please consider using one of the 32 headers found in section 17.4.1
.2 of the C++ standard. Examples include substituting the <X> header for the <X.
h> header for C++ includes, or <sstream> instead of the deprecated header <strst
ream.h>. To disable this warning use -Wno-deprecated.
world.cpp:7:2: warning: no newline at end of file
/tmp/cc3k9Mrc.o(.text+0x1b): In function `main':
: undefined reference to `std::cout'
/tmp/cc3k9Mrc.o(.text+0x20): In function `main':
: 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*)'
/tmp/cc3k9Mrc.o(.text+0x28): In function `main':
: 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> >&)'
/tmp/cc3k9Mrc.o(.text+0x30): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >::ope
rator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostrea
m<char, std::char_traits<char> >&))'
/tmp/cc3k9Mrc.o(.text+0x59): In function `__static_initialization_and_destructio
n_0(int, int)':
: undefined reference to `std::ios_base::Init::Init[in-charge]()'
/tmp/cc3k9Mrc.o(.text+0x8a): In function `__tcf_0':
: undefined reference to `std::ios_base::Init::~Init [in-charge]()'
/tmp/cc3k9Mrc.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status |
This is linking problems I know, and setting up libraries is one of my weak points. I ran ldconfig hoping that would solve the problems, but it doesn't, then I tried env-update too.
C programs compile fine. C++ programs compiled through portage seem to compile fine too. I don't have any flags for gcc outside of make.conf as I've had problems before with that. _________________ Some people are alive only because it's illegal to kill them. |
|
| Back to top |
|
 |
Braempje l33t


Joined: 31 Jan 2003 Posts: 748
|
Posted: Wed May 28, 2003 5:59 pm Post subject: |
|
|
| Just a wild guess: are your permissions on /usr/lib/gcc-lib right? |
|
| Back to top |
|
 |
MaRTiaN Tux's lil' helper

Joined: 22 Apr 2002 Posts: 85 Location: London
|
Posted: Wed May 28, 2003 6:03 pm Post subject: |
|
|
Something I've done has led to g++ working for all users. gcc is meant to get the language from the suffix, I'm using *.cpp (at least last time I coded in C++ on linux that seemed to be the case). It shouldn't be a problem as I can use g++.
The permissions on gcc-lib look fine to me. drwxr-xr-x
(any idea's on how to set CXXFLAGS outside of make.conf so it wont screw portage up?)
edit: Ok this is weird, with the same user, sometimes g++ works fine, sometimes not (see error above) in different sessions, if it doesn't work, logout and login and then it works. _________________ Some people are alive only because it's illegal to kill them. |
|
| Back to top |
|
 |
() l33t

Joined: 25 Nov 2002 Posts: 610
|
Posted: Wed May 28, 2003 7:13 pm Post subject: |
|
|
| Gcc isn't linking against the C++ stdlib by default, unlike g++. |
|
| Back to top |
|
 |
MaRTiaN Tux's lil' helper

Joined: 22 Apr 2002 Posts: 85 Location: London
|
Posted: Wed May 28, 2003 8:23 pm Post subject: |
|
|
Any way to get gcc to link against libstdc++ if it needs to by default? _________________ Some people are alive only because it's illegal to kill them. |
|
| Back to top |
|
 |
markkuk Guru

Joined: 29 Nov 2002 Posts: 446
|
Posted: Wed May 28, 2003 9:55 pm Post subject: |
|
|
| You must specify -lstdc++ on the command line if you use the "gcc" command to compile and link C++ programs. |
|
| Back to top |
|
 |
() l33t

Joined: 25 Nov 2002 Posts: 610
|
Posted: Thu May 29, 2003 11:49 am Post subject: |
|
|
| Calling g++ should in effect be the same as gcc -lstdc++? |
|
| Back to top |
|
 |
|