Advertisement

str=new char[103];

Started by April 28, 2003 10:21 PM
4 comments, last by tHiSiSbOb 21 years, 9 months ago
I am trying to program a few simple apps in C++ under Mandrake Linux using the gcc3.2 compiler. Everything works except the new operator. How can I get it working?>
----------------------------------------------------"Plant a tree. Remove a Bush" -A bumper sticker I saw.
Well, did you say char *str first?

<img src=http://webspace.utexas.edu/~mvdepala/random/resist-ignorance.png
Advertisement
yes, the error is that the new operator is "not defined"
----------------------------------------------------"Plant a tree. Remove a Bush" -A bumper sticker I saw.
Compile with g++ rather than gcc.

Tom L
refrain_from_stupidity( &me );
krumms, that would only be a problem if A) his setup does not recognize standard C++ file extensions as C++ files, or, B) he is not using a standard C++ file extension. Modern versions of gcc recognize that a .cpp or .cc or .cxx, etc. files are C++ files, and should compile and link accordingly.

Of course, you should definately at least try this first, and that might tell you what the problem is.

<img src=http://webspace.utexas.edu/~mvdepala/random/resist-ignorance.png
quote:
Original post by tHiSiSbOb
yes, the error is that the new operator is "not defined"


Do you mean something like this:

/tmp/ccyZ2uXU.o(.text+0x16): In function `main'':: undefined reference to `operator new[](unsigned)''/tmp/ccyZ2uXU.o(.text+0x2d): In function `main'':: undefined reference to `operator delete[](void*)''/tmp/ccyZ2uXU.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'' 



If so, krumms is right. Use g++ and not gcc. Gcc will invoke g++ to compile your code, but it won''t link with the C++ library. Either use g++ or explicitly link with libstdc++:

g++ -o progname source.cc

or

gcc -o progname source.cc -lstdc++


If it doesn''t help, try to provide more informations, like the exact error message.

Hope this helps.

This topic is closed to new replies.

Advertisement