This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: is STL usable with gcc 3.0?




| Hi,
| Sorry to send so much email to this list, but I've been having a really 
| horrible with gcc 3.0...the latest is problems getting STL to work with gcc 
| 3.0. On my system (RedHat Linux, RedHat Linux 2.2.18), a basic "hello 
| world" that uses STL crashes in a variety of ways. Take your basic "hello 
| world" program...
| 
| #include <stdio.h>
| #include <stdlib.h>
| #include <unistd.h>
| #include <vector>
| int main(int argc, char** argv) {
|    printf("hello world!\n");  exit(0);
| }
| 
| compiled with default options ("gcc hello.cpp")...
|
| 1) adding the line
| 
| std::vector<int> myvector;
| 
| yields the error
| 
| /tmp/cctISmpm.o: In function `__FRAME_BEGIN__':
| /tmp/cctISmpm.o(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
| collect2: ld returned 1 exit status
 
As a rule of thumb if you intend to compile C++ code, just use the g++
wrapper to compile your code since it is actually necessary to link
code utilizing containers/algorithms etc. of the STL because it links
in the standard C++ library and generally speaking just takes care of
passing the appropriate options to the compiler and linker. If you're
just using 'gcc hello.cpp' at least '-lstdc++' is missing from the
linker options. (`__gxx_personality_v0' is defined in libstdc++)

Next, if you're writing C++ code, it is encouraged to use a special
naming scheme when including headers:

If you're including C headers use '#include <cX>' instead of '#include <X.h>', 
if you're including C++ headers just use '#include <X>'.

This way you will avoid annoying warning messages.

| 2) adding the line
| 
| vector<int> myvector;
| 
| yields the error
| 
| hello.cpp:7: 'vector' is used as a type, but is not defined as a type.

'vector' is declared in the namespace 'std' and you have to specify
the namespace, otherwise it won't work...

| 3) adding the lines
| 
| typedef std::vector<int> mytype_t;
| 
| mytype_t myvector;
| 
| yields the error
| 
| /tmp/cc2HrKVq.o: In function `__FRAME_BEGIN__':
| /tmp/cc2HrKVq.o(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
| collect2: ld returned 1 exit status
| 
| Please advise...this is driving me insane!
| 
| thanks so much
| 
| Brent

Claudio


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]