gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

C/C++ > new and delete with devkitarm

#25121 - MumblyJoe - Tue Aug 17, 2004 2:57 am

Just quickly, I have never had any real problems with devkitarm that were not proven to be me bieng retarded so I'm sure this is the same deal.

When I use new/delete with devkitarm I get the following linker errors:

Code:
bssoundtest.o(.text+0x56): In function `main':
: undefined reference to `operator new[](unsigned long)'
bssoundtest.o(.text+0xd8): In function `main':
: undefined reference to `operator delete[](void*)'
bssoundtest.o(.text+0xe0): In function `main':
: undefined reference to `__gcj_personality_sj0'


If I explicitly link in libstdc++.a all sorts of other shit goes wrong so I don't know if I'm doing that right.

Anyway, if there is a solution I would love to hear it, even if its just "you cant use new and delete".
_________________
www.hungrydeveloper.com
Version 2.0 now up - guaranteed at least 100% more pleasing!

#25122 - tepples - Tue Aug 17, 2004 3:15 am

Are you using arm-elf-gcc or arm-elf-g++? When linking a C++ program, use the latter.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#25144 - MumblyJoe - Tue Aug 17, 2004 11:01 am

I'm using arm-elf-g++. Pretty much all I want new/delete for is to test out the BoyScout sound engine and see if it's reliable for what I'm doing.

Only way around it I can see unless anyone knows what I'm doing wrong, is to calculate myself the memory needed and allocate it at compile time...
_________________
www.hungrydeveloper.com
Version 2.0 now up - guaranteed at least 100% more pleasing!

#25145 - MumblyJoe - Tue Aug 17, 2004 11:16 am

in fact even if I use memory just declared in my program like so:

Code:
#include "/noodle/noodle.h"
#include "songo.h"

int main()
{
   using namespace noodle;

   u8 memforsong[cbssound::memneeded<songo>()];

   cbssound s((u8*)songo,memforsong);

   s.start();

   while(1)
   {
      while(display->vblank()!=160){}
      s.update();
   }

   return 0;
}


I still get this linker error:

Code:
bssoundtest.o(.text+0xec): In function `main':
: undefined reference to `__gxx_personality_sj0'


So I'm pretty stumped.
_________________
www.hungrydeveloper.com
Version 2.0 now up - guaranteed at least 100% more pleasing!

#25146 - MumblyJoe - Tue Aug 17, 2004 11:28 am

Sorry about the triple post but it appears enabling exceptions makes the problem go away... I have no idea why.
_________________
www.hungrydeveloper.com
Version 2.0 now up - guaranteed at least 100% more pleasing!

#25162 - torne - Tue Aug 17, 2004 3:51 pm

new likes to throw exceptions. More specifically, unlike malloc(), it doesn't return a null pointer on failure, it throws a bad_alloc exception. There exists a no-throw version of new in the ISO standard, used like this:
Code:
pointer = new(nothrow) your_type;

which returns null on failure and thus doesn't need exception support - include the header <new> to use this. I have no idea whether g++ actually supports this, though.