The method of adding C + + source files into SDK project compilation under mcuxpresso IDE


Hello, everyone. I’m a ruffian. I’m a real technical ruffian. What ruffian Heng introduced to you today isMethod of adding C + + source files into SDK project compilation under mcuxpresso IDE

Recently, a customer reported that some source files with. CPP suffix were added to the SDK project under the mcuxpresso ide. The functions in the. CPP source file could not be normally compiled and linked by the project, so the project could only be pulled out and then manually compiled by using the mcuxpresso tool chain and makefile.

PI Ziheng tried this problem quickly in mcuxpresso IDE, and it was true that, as the customer reported, it was impossible to directly compile the. Cpp file. This is not consistent with the experience of PI Ziheng in the IAR / keil MDK project. The process of adding. CPP source file and. C source file in IAR / keil MDK project is the same, and there is no need for any special settings from the IDE angle.

The function of mcuxpresso IDE is actually very powerful. Ruffian Heng doesn’t believe that it can’t directly compile. CPP files, so he has a lot of trouble and finally can compile. CPP files normally. I would like to share my experience with you.

1、 Prepare the experimental environment

First of all, we need to prepare the test environment, including the necessary software. The environment of ruffian scale is as follows:

2、 View project build information

Open classic SDK with mcuxpresso IDE_ 2.8.2_ EVK-MIMXRT1010\boards\evkmimxrt1010\demo_ apps\hello_ World routine, try build once, and you can see all the build information in the console window

In fact, a glance at the information in the console window is very helpful for understanding the engineering process of the mcuxpresso ide. In fact, the following three-step separation commands are summarized, but the IDE automatically executes these separated commands in sequence:

**** Build of configuration Debug for project evkmimxrt1010_ hello_ world ****

3、 Add C + + source file compile error

In order to test conveniently, PI Ziheng wrote a simple SW directly_ Delay() soft delay function, put it in the following SW_ delay.cpp/h In the source file, these two new source files are placed in the_ 11.2.0_ 4120\workspace\evkmimxrt1010_ hello_ In the world source directory, and then in the project hello_ Add a sentence SW to the world. C file_ Call code for delay().

#include "sw_delay.h"
void sw_delay(uint32_t n)
    while (n != 0U)

#include #if defined(__cplusplus)
extern "C" {
void sw_delay(uint32_t n);
#if defined(__cplusplus)

Now we’re building with SW_ delay.cpp File project, get the following error, this error is not found SW_ The delay() function is defined because SW_ The delay() function code is placed in the. Cpp file (if it is in the. C file, the compilation is normal). If you look through all the compiled logs, you can’t find out about SW_ delay.cpp File compilation information, it looks like. Cpp file is automatically ignored.

4、 Let mcuxpresso ide compile c + + files correctly

4.1 activate C + + compiler

In the second section, we analyzed the build information. The compilation of. C files is implemented by activating MCU c compiler. Now. CPP files are automatically ignored. It is estimated that the C + + compiler has not been enabled. Let’s start the C + + compiler and add a code to the. Project file. The details are as follows:

The code that opens the C + + compiler takes effect immediately. You don’t need to close and restart the IDE project. Now let’s build the project again. At this time, we have SW in the compilation log_ delay.cpp It seems that we have finished.

4.2 indicate link file for C + + linker

Things are not so simple. Although the. Cpp file can be compiled, there are more errors in the final build of the project. The information in the log shows that some C standard library functions called in the code and some section names and stack names defined in the link file can not be found in the link phase. It seems that there is a problem with the linked file.

Open the project property settings. Under the settings of C / C + + build, you can see that after the C + + compiler is activated, the MCU C + + compiler option is added, and the MCU C + + linker option is upgraded to the MCU C + + linker option. However, the linker script is not specified in the MCU C + + linker option (there is a link file in the MCU C linker option). In this case, we only need to check manage linker Script, you can set the link file.

After setting the apply property, edit the project again, and finally see 0 errors and 0 warnings. In order to ensure that in case, you can check whether there is SW in the map file_ The delay() function means that the. Cpp file has been compiled and linked normally.

4.3 setting reference paths and macros for C + + compiler (optional)

Finally, we need to remind you that if the cpp file also depends on some paths and macros, these paths and macros need to be filled into the corresponding settings of MCU C + + compiler option. The default path and macro definition are empty.

So far, the method of adding C + + source files into SDK project compilation under mcuxpresso IDE is finished. Where is the applause~~~

Welcome to subscribe

The article will be posted to me at the same timeBlog Garden HomepageCSDN home pageZhihu HomepageWeChat official accountOn the platform.

Wechat search“Ruffian scale embedded“Or scan the QR code below, and you can read it for the first time on your mobile phone.