library error with C++ application

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

library error with C++ application

Jump to solution
659 Views
OldNick
Contributor IV

Sorry if I have already posted this, but I am gettting hopelessly confused...just trying to add a simple C++ file to one of the standard MQX-towerK40 examples (hello.ewp)

 

IAR ewarm 6.2, project settings exactly as supplied, with one change - compiler c or c++ "Auto" (based on extension)

C++ version is EEC++

 

#include <iostream>
#include <mqx.h>
#include <bsp.h>

void printstring(void)
{
  cout<<"hello"<<endl;
}

 

The simple act of adding this file to the build (even if you never call printstring() !) causes the linker to warn about there being no heap.

 

If I add the operator overloads to the cpp file in the same way that the PEG++ librar build uses (which DOES work with MQX), the project compiles and links with 0 errors 0 warnings.

 

But the debugger never gets to main.:robotmad:

Does anybody know what is going on?

 

PS> There are a bunch of similar questions in th ancient history on this forum, but I haven't seen that anybody had it answered yet.  It would be nice if there was a FAQ on how to make C++ apps work with MQX, or at least make it clear that it can't be done.

 

0 Kudos
1 Solution
384 Views
KJFPE
Contributor III

Hi 

 

If you plase the following in your klinker file 

 

define block HEAP with size = 0x2000, alignment = 8{ };

place in RAM_region {block HEAP};

 

it will work

View solution in original post

0 Kudos
2 Replies
385 Views
KJFPE
Contributor III

Hi 

 

If you plase the following in your klinker file 

 

define block HEAP with size = 0x2000, alignment = 8{ };

place in RAM_region {block HEAP};

 

it will work

0 Kudos
384 Views
OldNick
Contributor IV

KJFPE wrote:

Hi 

 

If you plase the following in your klinker file 

 

define block HEAP with size = 0x2000, alignment = 8{ };

place in RAM_region {block HEAP};

 

it will work


it might work, but is it safe?:robotwink:

 

MQX does all its own memory management (I think).

 

Let's say we need to kill the C++thead due to an RTOS error.  What happens to cout if it is on the heap?  There is no explicit malloc. for cout...can cout be deleted?  Looks like a recipe for a memory leak?

 

My belief is that a C++ thread should be able to be written that runs in MQX without having an externally defined heap.   I know that this can be done because PEG+ is integrated with MQX and runs (we already discussed this).  But PEG+ might not use stdio libraries so might avoid this issue by "accident"?

 

Since MQX insists on taking over the whole processor, startup code, IO pins, timers, device drivers etc. it would be kind of good to know the limitations of a mixed language environment.

 

In the more general case, I am simply looking for a way to configure either complier or linker or both which permits C++ application code to run on top of MQX as if MQX were a C++ RTL, but safely.

 

the fallback position is to abandon C++ altogether and try to write object oriented "C". ( (void *) pthis->do_stuff(void * paramset )  

 

It works, but is it a good idea?

 

:robottongue:

0 Kudos