#### Archived

This topic is now archived and is closed to further replies.

# str=new char[103];

## Recommended Posts

tHiSiSbOb    463
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?>

##### Share on other sites
Strife    374
Well, did you say char *str first?

##### Share on other sites
tHiSiSbOb    463
yes, the error is that the new operator is "not defined"

##### Share on other sites
krumms    126
Compile with g++ rather than gcc.

Tom L

##### Share on other sites
Strife    374
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.

##### Share on other sites
Guest Anonymous Poster
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.