Solved gcc on .cpp file gives undefined reference to `operator new[]

I'm trying to port something to FreeBSD, and the original source bundle uses gcc, and (among other things) compiles a few .cpp files.

When I installed FreeBSD's gcc package, I noticed this text:
Code:
---------- Message for gcc-4.8.4_3:

To ensure binaries built with this toolchain find appropriate versions
of the necessary run-time libraries, you may want to link using
  -Wl,-rpath=/usr/local/lib/gcc48
But before using that on the software I'm porting, as a test I tried compiling this file 1.cpp:
Code:
int main(void)
{
  int *something;
  something=new int[8];
  return 0;
}
... using this command:
Code:
gcc -Wl,-rpath=/usr/local/lib/gcc48 1.cpp -o 1
Directory /usr/local/lib/gcc48 has tons of files in it, incidentally, leading me to think that I had probably installed gcc correctly. But the compilation attempt generated this message:
Code:
/tmp//ccBrMZU7.o: In function 'main':
1.cpp:(.text+0x11): undefined reference to `operator new[](unsigned int)'
collect2: error: ld returned 1 exit status
I'm sure it's something really simple. What am I doing wrong?
 
Incredibly, when I installed gcc48, it provided nothing called g++. On the theory that perhaps gcc tests argv[0] for something, I tried creating a symbolic link at /usr/local/bin/g++ to /usr/local/bin/gcc, and used g++. This did not fix the problem. Introducing command line option -lstdcc++, however, did.
 
Yes that's according to the policy of not installing binaries with same names there could be in the base system, FreeBSD 8 and 9 still have /usr/bin/gcc|g++|etc.
 
Back
Top