Sorry for another stupid question.
Is there a file somewhere that i need to link to let me use c++ commands? ATM i can't use 'new' to setup some classes that i want to use.
Is there something like xlibcpp that i'm missing?
The problem is that the libc code that is provided with OpenXDK at the moment does not support the new/delete operators. You may be able to find a third-party library that provides this code... not sure how successful that search will be, though.
Thanks for that. At least i know now :D
Do you have a relative timeframe on when this will be achieved? I can work from static allocation for the time being (probably a good idea, since we know the maximum memory ceiling) but I far prefer dynamic allocation.
No specific timeframe in mind. At the time I commented, the libc that was in use was the old MS-based libc.
There is a chance that it might just magically work with the newlib based libc (I recall reading somewhere that the default new and delete operators just use the normal malloc and free implementations).
At this stage, getting audio and networking is highest on my priority list. Feel free to give it a go and report your results back here...
I am currently writing a XBox development framework around OpenXDK/SDL using C++. Converting to C++ requires a few hoops to be jumped through but is quite straightforward really.
To use C++, you need to do the following :-
1. I modified the sample makefile on the OpenXDK such that it used g++ as the compiler. If you do this, you need to remove -std=gnu99 and -ffreestanding from the CC_FLAGS. I also changed the line .c.o: to .cpp.o:
2. You need to implement new and delete. This is actually easier than it sounds ie.
void * operator new ( size_t size )
return( malloc( size ) );
void * operator new  ( size_t size )
return( malloc( size ) );
void operator delete( void *p )
free( p );
void operator delete  ( void * p )
free( p );
The C++ compiler will handle the calling of the destructor prior to freeing the memory.
Hopefully this will be implemented in the newlib standard library before the next release of OpenXDK.
3. You will need to encapsulate the function prototypes in some of the header files with extern "C" to prevent name mangling. To do this, place the following code just before the first function prototype in each header file :
and just after the last function prototype :
I don't have a list of all the header files that need to be modified but if you get "undefined blah" errors then you can bet that they need the above code.
As with new and delete, hopefully this change can be made before the next release of OpenXDK.
4. You need to declare XBoxStartup in your main cpp file thus:
extern "C" void XBoxStartup()
again to prevent name mangling upsetting things.
5. The most difficult part of the conversion to c++ was finding out why the virtual tables were not being linked in to the final code. Without virtual tables, you cannot create virtual functions or abstract classes. Eventually I found that you can link in the gcc standard library which will solve this problem. This should not cause a conflict with the newlib standard library as you should be using the -nostdlib flag in the compiler settings. To link in the standard library, add the following switch -lstdc++ to the LD_LIBS line in the make file.
Sorry for such a long post but perhaps it will help others with the switch over to c++.
Coming from a background in Java developing, I am used to OO programming langauges. The way I read what your saying, I would be able create objects and such, which i found out I couldn't after hours of trying to work out why the compiler was having issues with the keyword "new".
Is this correct? I'm still pretty new to c/c++.
Wow! Thanks. I'm looking forward to trying this immediately.
Log in to post a comment.
Sign up for the SourceForge newsletter:
You seem to have CSS turned off.
Please don't fill out this field.