How to code in c++ and c with DAVE

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Not applicable
Hello,

even though the gnu toolchain provides a c++ compiler and it is bundled with DAVE I can not use it.

But I am unabled to integrate C++ into the toolchain. Why?

Using C++ at some places would help development a lot.

Thanks in advance.
0 Likes
30 Replies
Not applicable
HI,

You may refer to the follow threads on mixing c and c++ in your project.

Forum threads:
http://www.infineonforums.com/threads/3234-DAVE-C-project
http://www.infineonforums.com/threads/1677-Programming-in-c?

Hints to mix c and c++:
https://isocpp.org/wiki/faq/mixing-c-and-cpp

Regards,
Daryl
0 Likes
Not applicable
I already found these informations. But it is no help. Since I cannot configure a c++ compiler in DAVE 4.1.x. The toolchain only shows gcc and not g++.
Renaming the call to g++ from gcc is not a solution because one is missing all options to configure g++
0 Likes
Not applicable
Hi,

It should be possible to compile using the C++ compiler by renaming at least one of your project files from .c to .cpp extension.

Another way is to change the project settings:
Goto:
Project -> Active Project Properties -> C/C++ Build -> Settings -> ARM -GCC C Compiler.
- Under Command: "${ARM_GCC_HOME}/bin/arm-none-eabi-gcc"
- Change arm-none-eabi-gcc to arm-none-eabi-g++

1815.attach

Regards,
Daryl
0 Likes
Not applicable
1816.attach

As i have written, renaming is no clever posibility, because the configs in eclipse are still expecting a gcc and not g++ and therefore the GUI config settings do not match.
Why is ARM-G++-Compiler (and linker) excluded in the ARM-GCC-Applikation toolchain of DAVE?

It is not problem to use g++ in eclipse with a proper setup toolchain.
0 Likes
Not applicable
Just to clear things up.

After adding a .cpp file the c++ settings show up, as you said.

Is the startup code and the linkefile able to handle c++ correct?
0 Likes
Not applicable
HI,

Yes, there is no issue with the handling.

Regards,
Daryl
0 Likes
Not applicable
From what I tested, this is NOT correct!

Constuctors of global declarated Objects are NOT called.
0 Likes
Not applicable
Hi,

Can you share across your project for us to check on this.


Regards,
Daryl
0 Likes
Not applicable
Clean DAVE-CE project.

Very simple:

testing.cpp

class Try {
public:
const static int constVal = 100; // Triggers the compile warning, see below
int tryVal;
Try() {
// If you set a breakpoint here, you see that the constructor is not run.
tryVal = 10;
}
}

main.cpp

// Outside of main (global).
Try object();

int main {
// if you step here with the debugger you see that tryVal is not 10.
}



And if you got some public "const static" or "static" elements in the class the compiler complains:

main.cpp:43: undefined reference to `__dso_handle'
"ARM-GCC-49/bin/arm-none-eabi-g++" -T"../linker_script.ld" -nostartfiles -Xlinker --gc-sections -Wl,-Map,C++.map -mfloat-abi=softfp -mfpu=fpv4-sp-d16 -mcpu=cortex-m4 -mthumb -g -gdwarf-2 -o "C++.elf" "@objects.rsp" -lm
makefile:71: recipe for target 'C++.elf' failed
arm-gcc-49/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld.exe: C++.elf: hidden symbol `__dso_handle' isn't defined
arm-gcc-49/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld.exe: final link failed: Bad value


So i am pretty sure, that the startup files don't initialize C++ stuff correctly.
0 Likes
lock attach
Attachments are accessible only for community members.
Not applicable
HI,

The code was able to run after making a slight change ..
The project is attached.


1840.attach

Regards,
Daryl
0 Likes
Not applicable
Ok, i see. The constructor is only run, if the object is used in any way. Otherwise it will be optimized and stipped out completely.
0 Likes
Not applicable
Still fails, if you got DEstuctors in the class you use static or global!

-fno-use-cxa-atexit needed as g++ option.
0 Likes
Not applicable
Hi Holger,

I have filed an eticket #983215007 for this case. You can track the status of this in DAVE Problem Tracking link below.
http://www.infineonforums.com/support/dave3/index.php?option=com_maqmahelpdesk&Itemid=0&id_workgroup...

Regards,
Daryl
0 Likes
Not applicable
Thank you. I will follow.

Another thing which is not as it should be.

In C++ "mode" it seems the build does not rebuild if a header file is chanced.

If I change a header.h and leave the corresponding header.cpp alone then the code is not rebuild even if header.h is included and the class used in main.cpp.

Pretty odd!
0 Likes
Not applicable
I changed this posting:
http://www.infineonforums.com/threads/3758-How-to-code-in-c-and-c-with-DAVE?p=11231&viewfull=1#post1...
The problem is with DEstructors. Not constructors.
0 Likes
Not applicable
Clarification:

E.g. DAVE (actual) CE Project with the following code.

main.cpp:
#include "TestClass.h"

int main(void) {
DAVE_STATUS_t status;

status = DAVE_Init(); /* Initialization of DAVE APPs */

if (status == DAVE_STATUS_FAILURE) {
/* Placeholder for error handler code. The while loop below can be replaced with an user error handler. */
XMC_DEBUG("DAVE APPs initialization failed\n");

while (1U) {

}
}

TestClass testObject = TestClass();
testObject.doNothing();

int variable = TestClass::staticVal;

/* Placeholder for user application code. The while loop below can be replaced with user application code. */
while (1U) {
variable++;
}
}


TestClass.h:
#ifndef TESTCLASS_H_
#define TESTCLASS_H_

class TestClass {
public:
const static int staticVal = 10;

TestClass();
virtual ~TestClass();

void doNothing(void);
};

#endif /* TESTCLASS_H_ */



TestClass.cpp:
#include 

TestClass::TestClass() {
// TODO Auto-generated constructor stub

}

TestClass::~TestClass() {
// TODO Auto-generated destructor stub
}

void TestClass::doNothing(void) {

}


If staticVal is changed in TestClass.h and the file is safed, the code is NOT rebuild if one runs "Build Active Project"!
0 Likes
Not applicable
And a question about the ticket system:
E.g. here
http://www.infineonforums.com/support/dave3/index.php?option=com_maqmahelpdesk&Itemid=0&id_workgroup...

Is it possible to monitor a ticket? To get an email as soon as it changes or even to get a list of all monitored tickets?
0 Likes
Not applicable
Any feedback on the "does not build although .h file changed when there are .cpp files" problem?
0 Likes
Not applicable
Hi, Holger,

1. "Is it possible to monitor a ticket? To get an email as soon as it changes or even to get a list of all monitored tickets? "
- For the DAVE Problem Tracking, if you have raise the ticket, any updates in the ticket will be sent to you via the email. However, there's no feature to subscribe to the individual ticket for users.

2. "Any feedback on the "does not build although .h file changed when there are .cpp files" problem? "
- Currently we are working on this issue. I can update once it is available.

Regards,
Daryl
0 Likes
Not applicable
Thanks for the feedback.

1. Would be nice. I could check if a "stopper" is removed without constantly checking it.
2. Thank you. I am looking forward.
0 Likes
Not applicable
Daryl Neo wrote:

2. "Any feedback on the "does not build although .h file changed when there are .cpp files" problem? "
- Currently we are working on this issue. I can update once it is available.

You have seen this?
http://www.infineonforums.com/threads/3895-Solution-for-recompile-problem-in-c?p=11538&viewfull=1#po...
0 Likes
ningareddy_moda
Employee
Employee
Hi Holger,

Please replace the existing contents of ARM-GCC C++ Compiler "Command Line Pattern"

From:

${CCACHE} ${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}

To:

${COMMAND} ${FLAGS} -MMD -MT ${OUTPUT_PREFIX}${OUTPUT} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}

As shown in the image C++Settings.png


Let me know your feedback
Best Regards
Ningareddy
0 Likes
Not applicable
🙂 This is exactly what I have written in this post:
http://www.infineonforums.com/threads/3895-Solution-for-recompile-problem-in-c?p=11539&viewfull=1#po...

Well, nice to see that my solution is correct. I hope to see this in the next release.

What about the same line for C and ASM? I quess it does not hurt.
0 Likes
ningareddy_moda
Employee
Employee
We will add this in our next DAVE release.

You are right, adding for C and ASM should not hurt. I will check and update
0 Likes
Not applicable
how is the state now? Are there any start-up und linker script for c++ programming?
0 Likes
Not applicable
C++ works for me. All summed up above. A special option on g++ to allow global instatiation of classes with destructors. Some command line changes to get partial compiling.

Works flawless as long as you keep it single-threaded even if you use dynamic memory, which should be last resort anyways in C++ nowadays.

As soon as you want multi-threading with any RTOS you should be alert on malloc/new and everything in STL without a self written allocator and proper locking on everything which is not reeentrant (basically everything), because you will shoot youself in the feet.
The compiler and libs are compiled in process-model "single" which means there are no internal countermeasures for atomics, threads, ...
You really need to know what you do if you want to go this way.
0 Likes
Not applicable
🙂 good to hear that.
0 Likes
Not applicable
HRusch wrote:
Still fails, if you got DEstuctors in the class you use static or global!

-fno-use-cxa-atexit needed as g++ option.

After some investigation I can say that -fno-use-cxa-atexi is not needed, but ...

The symbol __dso_handle is missing in the Infineon startup code.

Easy fix:
void *__dso_handle;

@Daryl Neo you may alter the ticket, I cant do it.
0 Likes
Not applicable
HI Holger,

Thanks for the investigation. I have alter the eticket. 🙂

Regards,
Daryl
0 Likes
Not applicable
Thank you.

PS: I would love to see infineon being active on this: https://community.arm.com/groups/tools/blog/2016/03/11/cmsis-a-proposal-for-a-future-cmsis-written-i...
Or driving something into the same direction.
0 Likes