Using c++ in MQX project

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

Using c++ in MQX project

1,494 Views
amleng
Contributor IV

Hello all,

I try to use c++ classes in my mqx project. I have file system, rtcs and usb middlewares in this project. I added a cpp file to the project but I get error on brackets! I'm sure the notation/syntax is correct. I use CW 10.2. I enabled cpp in bsp as well. any suggestion?

Thanks!

0 Kudos
9 Replies

822 Views
ivanpajuelo
Contributor II

I found a C++ related error on some RTCS and USB headers that causes you can't link your project.

I'm not sure if this is your problem but in any case you need to add

extern "C" {

#include <header_not_linking>

}

to your source if you don't want to modify MQX headers.

If your problem is a compiler error, Can you put the error description and the piece of code where this error theoretically is?

822 Views
c0170
Senior Contributor III

Hello Ivan,

thanks for this reminder .I totally forgot, those headers and linkage of C++ were fixed while ago , it will be fixed in next release. It could have been missed in previous releases. Sorry for troubles :smileyhappy:

Regards,

MartinK

0 Kudos

822 Views
MarkP_
Contributor V

Hi,

Which version of CW you are using? Special Edition (free) does not support C++.

At C++ project creation there is a mention:

"C++ is only available with the Professional Edition and the Standard Edition when the Enhanced Compiler Option is installed."

~Mark


0 Kudos

822 Views
amleng
Contributor IV

Hi Martink,

I have two basic question here:

1- how can I create new simple c++ application?

2- What do you mean by link MQX libs? How can I link bsp/psp to the application? isn't it done automatically during project creation?

0 Kudos

822 Views
Martin_
NXP Employee
NXP Employee

In MQX 3.8.1, build MQX libs with #define BSP_ENABLE_CPP 1 in your user_config.h.

Now refer to the example application called "cplus".
c:\Freescale\Freescale MQX 3.8\mqx\examples\cplus\
This one is hello world type of an application using MQX in C++.

Ad 1.
either: create new bare metal project and then add MQX *.h and *.a file (header and libs) of your board (in the \lib\<board_name>.<compiler> folder of your MQX installation directory)
to the compiler, assembler and linker properties of your build target.

or: use CW 10.2 New Project Wizard to create a new MQX 3.8 application, select your board and then example "cplus" project. This will create a new "cplus" application in your workspace, with all compiler, assembler and linker properties already set up for linkage with MQX 3.8.1 libraries.

Ad 2.
If you create a new bare metal application, you shall configure properties of compiler/assembler/linker manually in the properties of your build target.
If you create a new MQX 3.8 application, the new project wizard will configure the paths to the MQX header files and libraries for your <board_name>.<compiler> automatically.


If you're mixing C++ and C source files:
-make sure names of the source file(s) are not shared, for example, hello.cpp and hello.c should not be in one project
-you can call C functions from C++ source file. you just need to tell the C++ compiler that it should link the C function as a C object, using keyword: extern "C"

0 Kudos

822 Views
amleng
Contributor IV

what I need to do is mixing C with C++ in a MQX project using CW 10.2 on K60 platform. I wont use C++ library function but I need to use classes and other OO concepts.

0 Kudos

822 Views
c0170
Senior Contributor III

Hello Sina Moshksar,

create new simple c++ application with two classes for instance which links your MQX libs (I would start only with bsp/psp) and build it if it passes without any error.

We have no much information what errors you run into. If I build new application with some c++ syntax for k60 in CW 10.2, application builds without errors.

Regards,

MartinK

0 Kudos

822 Views
amleng
Contributor IV

yes I did. it didnt help. I found the following changes for coldfire but not for kinetis (ARM) family.

-              in Project -> Properties -> C/C++ Build -> Settings -> Librarian

o             set “Model” to “ewl_c++”

-              in Project -> Properties -> C/C++ Build -> Settings -> ColdFire Compiler -> Input

o             add "${MCUToolsBaseDir}/ColdFire_Support/ewl/EWL_C++/include" in “System Path”

-              in Project -> Properties -> C/C++ Build -> Settings -> ColdFire Compiler -> Language Settings

o             check “Force C++ Compilation”

o             check “Enable C++ Exceptions”

o             check “Enable RTTI”

0 Kudos

822 Views
c0170
Senior Contributor III

Hello,

BSPCFG_ENABLE_CPP is set to 1 and was rebuilded bsp? Have you tried to turn on a setting "Force C++ compilation"?

Regards,

MartinK

0 Kudos