C++ Usage Issues - Problems, Solutions, and Suggestions

Robert S. Grimes rsg at alum.mit.edu
Thu Jun 21 16:07:11 UTC 2007


Joel Sherrill wrote:
> Robert S. Grimes wrote:
>> Ralf Corsepius wrote:
>>  
>>> No, using "<target>-gcc -lstdc++" is never correct. You have to use
>>> "<target>-g++" instead of "<target>-gcc" to link c++ code.
>>>       
>> Oops, I missed that - of course, I didn't know that I had.  I was about
>> to ask, but then a bit of poking around led me to virtex.cfg, where
>> there is a make-cxx-exe rule, which indeed fixes it correctly -
>> Thanks Ralf!
>>
>> For C++ applications, change it to this:
>>
>>     ${ARCH}/xxx-your-program-here: ${OBJS} ${LINK_FILES}
>>         $(make-cxx-exe)
>>
>> Joel, maybe this should also be in the Template file, at least a
>> commented-out version?  I'm not sure I ever would have figured out the
>> correct way to link if Ralf had not corrected me.
>>   
> That's not a bad idea.  I just did it.
Thanks - it should help keep us rookie C++ coders from hassling you
hardened C-jockeys! ;-)
>>>
> I just committed a fix for this and the others in the libnetworking/rtems
> directory that were not doing an extern "C".
I see that you used the old #ifdef __cplusplus approach.  Should we use
the _BEGIN_STD_C/_END_STD_C macros that are used elsewhere, such as
$TARGET/include/stdlib.h?  See the $TARGET/include/_ansi.h file, at the
bottom:

    /*  ISO C++.  */

    #ifdef __cplusplus
    #if !(defined(_BEGIN_STD_C) && defined(_END_STD_C))
    #ifdef _HAVE_STD_CXX
    #define _BEGIN_STD_C namespace std { extern "C" {
    #define _END_STD_C  } }
    #else
    #define _BEGIN_STD_C extern "C" {
    #define _END_STD_C  }
    #endif
    #endif
    #else
    #define _BEGIN_STD_C
    #define _END_STD_C
    #endif

This way, namespace std is handled correctly too.

Take care,
-Bob



More information about the users mailing list