undefined reference to `__gxx_personality_v0'

K

Ken

Hi,

When I compile a c/c++ program named softlines.cpp here
http://linuxdevcenter.com/linux/2003/05/15/examples/softlines.cpp

I got error like below, could somebody help provide suggestion?

$ gcc -o softlines softlines.c `sdl-config --cflags --libs`
softlines.o: In function `main':
softlines.cpp:(.text+0x8e6): undefined reference to `operator new
(unsigned int)'
softlines.cpp:(.text+0x980): undefined reference to `operator new
(unsigned int)'
softlines.cpp:(.text+0xa1a): undefined reference to `operator new
(unsigned int)'
softlines.o:(.eh_frame+0x11): undefined reference to
`__gxx_personality_v0'
collect2: ld returned 1 exit status
 
B

Beej Jorgensen

Ken said:
$ gcc -o softlines softlines.c `sdl-config --cflags --libs`

Google almost always has the answers to these questions faster than
Usenet, so if you'd Googled for it, you'd already be on your way instead
of needing to wait and needing to read answers that tell you to use
Google. :)

http://www.google.com/search?hl=en&q=undefined+reference+to+__gxx_personality_v0

[ http://tinyurl.com/yb8v76x ]

But the answer is: use g++ instead of gcc.

And ask C++ questions on comp.lang.c++, not comp.lang.c.

-Beej
 
J

Jens Thoms Toerring

Ken said:
When I compile a c/c++ program named softlines.cpp here
http://linuxdevcenter.com/linux/2003/05/15/examples/softlines.cpp

There are no C/C++ programs, you either write in C or C++,
which are two different languages - while a number of C pro-
grams can be compiled with a C++ compiler (but not all), the
reverse is hardly ever possible.
I got error like below, could somebody help provide suggestion?
$ gcc -o softlines softlines.c `sdl-config --cflags --libs`
softlines.o: In function `main':
softlines.cpp:(.text+0x8e6): undefined reference to `operator new
(unsigned int)'
softlines.cpp:(.text+0x980): undefined reference to `operator new
(unsigned int)'
softlines.cpp:(.text+0xa1a): undefined reference to `operator new
(unsigned int)'
softlines.o:(.eh_frame+0x11): undefined reference to
`__gxx_personality_v0'
collect2: ld returned 1 exit status

Looks a lot as if you are trying to compile a C++ program
as if it would be in C. First thing you should do is to
use the original file name ('softlines.cpp' instead of
'softlines.c', signaling that it'ss a C++ program). Second
thing is to invoke the C++ compiler by using 'g++' instead
of 'gcc'. So try

g++ -o softlines softlines.cpp `sdl-config --cflags --libs`

And if you have questions about the language the program is
written please in ask in comp.lang.c++ ;-)

Regards, Jens
 
S

Seebs

Hi,

When I compile a c/c++ program named softlines.cpp here

There is no such thing as a "c/c++" program. C and C++ are different
languages.

I'm not just being a snide jerk. This is, in fact, your problem.

Note: ".cpp".
I got error like below, could somebody help provide suggestion?
$ gcc -o softlines softlines.c `sdl-config --cflags --libs`

gcc compiles multiple languages (not just C and C++, also Objective-C, and
possibly others).

You say here that you're referring to "softlines.c". But then:
softlines.o: In function `main':
softlines.cpp:(.text+0x8e6): undefined reference to `operator new
(unsigned int)'

Here you say ".cpp".

In short, the error messages you display here probably didn't come
from the command line you showed us. That makes this a pretty bad bug
report. Be really careful about "cleaning up" a report by changing
things you think don't matter.

This isn't really topical to C, but since I happen to know, I'll pass on
the implementation-specific magic:

gcc will pick a language usually based on the suffix of the file, but it
is generally best not to bet on this. I would suggest that you try using
the "g++" wrapper, which will usually try for C++ by default.

More generally, this is really not a question about C at all; it's a question
about your host system and implementation, which is presumably some variety
of Unix-like system (probably?), so try a group suited to that if this
isn't enough to get you unstuck.

-s
 
K

Keith Thompson

Seebs said:
gcc will pick a language usually based on the suffix of the file, but it
is generally best not to bet on this. I would suggest that you try using
the "g++" wrapper, which will usually try for C++ by default.

<OT>
That makes it sound like the gcc command doesn't reliably detect
that "foo.cpp" is a C++ source file, but that's not the issue.

"gcc foo.cpp" will reliably compile foo.cpp as C++ source, but
"g++ foo.cpp" still works quite differently than "gcc foo.cpp".

I *think* that "gcc -c foo.cpp" and "g++ -c foo.cpp" may be
equivalent, or nearly so, but don't quote me on that.

For details consult the gcc documentation (or another newsgroup).
Or just use "g++" rather than "gcc" whenever you're compiling C++
sources, and you don't have to care about the details.
More generally, this is really not a question about C at all; it's a
question about your host system and implementation, which is
presumably some variety of Unix-like system (probably?), so try a
group suited to that if this isn't enough to get you unstuck.

Right.
 
L

Lew Pitcher

<OT>
That makes it sound like the gcc command doesn't reliably detect
that "foo.cpp" is a C++ source file, but that's not the issue.

"gcc foo.cpp" will reliably compile foo.cpp as C++ source, but
"g++ foo.cpp" still works quite differently than "gcc foo.cpp".

I *think* that "gcc -c foo.cpp" and "g++ -c foo.cpp" may be
equivalent, or nearly so, but don't quote me on that.

You are correct. From the gcc manual page:
C++ source files conventionally use one of the suffixes .C, .cc, .cpp,
.CPP, .c++, .cp, or .cxx; C++ header files often use .hh or .H; and
preprocessed C++ files use the suffix .ii. GCC recognizes files with
these names and compiles them as C++ programs even if you call the com-
piler the same way as for compiling C programs (usually with the name
gcc).

However, C++ programs often require class libraries as well as a com-
piler that understands the C++ language---and under some circumstances,
you might want to compile programs or header files from standard input,
or otherwise without a suffix that flags them as C++ programs. You
might also like to precompile a C header file with a .h extension to be
used in C++ compilations. g++ is a program that calls GCC with the
default language set to C++, and automatically specifies linking
against the C++ library. On many systems, g++ is also installed with
the name c++.

For details consult the gcc documentation (or another newsgroup).
Or just use "g++" rather than "gcc" whenever you're compiling C++
sources, and you don't have to care about the details.


Right.

--
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I'm doing. ------
 
S

Seebs

That makes it sound like the gcc command doesn't reliably detect
that "foo.cpp" is a C++ source file, but that's not the issue.

I wouldn't have known. I don't use C++. :) I just have general experience
that attempts to guess intent from file suffixes have a surprisingly high
failure rate. (What kind of file is ".bin"?)

-s
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top