How to add a cpp file into c project in MCUXpresso IDE

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

How to add a cpp file into c project in MCUXpresso IDE

5,201 Views
misterbee
Contributor II

I took a sample of freertos_hello from the SDK, build and run on target and it is running fine. I use MCUXpresso IDE.

 

I want to add a task entry APP_sensorTask() inside main(). The definition of this task entry is in App.h like following:

#ifndef APP_APP_H_
#define APP_APP_H_

#ifdef __cplusplus
extern "C" {
#endif

// App task entries.
void APP_sensorTask(void *argument);

#ifdef __cplusplus
}
#endif
#endif /* APP_APP_H_ */

 

Then the implementation is in App.cpp like following:

// Project includes.
#include "App.h"

void APP_sensorTask(void *argument) {
	for (;;) {
			// TODO.
	    }
}

 

Then I include App.h inside the main() file.

But this creates linking error:

source/main.c:60: undefined reference to `APP_sensorTask'

 

This means the project base not recognizing and compiling this .cpp file. I have been using this on another project using another IDE and it works fine. Anything I miss here?

0 Kudos
21 Replies

4,941 Views
garkbeda43
Contributor I

I use mostly Segger Embedded Studio now. Runs on Linux, and supports multiple vendors. At one point I got tired of installing another 1GB vendor-specific toolchain just for one board.

0 Kudos

5,066 Views
davenadler
Senior Contributor I

@misterbee- Your project needs to be a C++ project, otherwise you'll be missing stuff you need.
Its no problem to convert an existing project, I've done this many times as our applications are primarily C++.
Basically you just need to:
   File > New menu and then select ‘Convert to a C/C++ Project (Adds C/C++ Nature)
For some more explanation, see:
https://mcuoneclipse.com/2020/07/11/from-c-to-c-converting-eclipse-c-projekts/ 
https://dzone.com/articles/from-c-to-c-converting-eclipse-c-projects 
Or just google: https://bfy.tw/T93v 
Hope that helps!
Best Regards, Dave

PS: Sorry nobody on this forum gave you this simple answer promptly, aaarrggg...

PPS: Beware of using C++ exceptions! Not thread-safe as distributed by ARM and NXP...

0 Kudos

5,048 Views
frank_m
Senior Contributor III

> PS: Sorry nobody on this forum gave you this simple answer promptly, aaarrggg...

Oh yes, I did. Though sometimes, experience is the better teacher.

0 Kudos

5,051 Views
misterbee
Contributor II

Thank you @davenadler , I did as you suggested but I had this error after clean build:

 

Building target: lpcxpresso54114_freertos_hello.axf
Invoking: MCU C++ Linker
arm-none-eabi-c++ -nostdlib -L"C:\Users\iotlab0035\Documents\MCUXpressoIDE_11.5.1_7266\workspace\lpcxpresso54114_freertos_hello\LPC54114\mcuxpresso" -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -o "lpcxpresso54114_freertos_hello.axf" ./utilities/fsl_assert.o ./utilities/fsl_debug_console.o ./utilities/fsl_str.o ./startup/boot_multicore_slave.o ./startup/startup_lpc5411x.o ./source/freertos_hello.o ./source/semihost_hardfault.o ./freertos/freertos_kernel/portable/MemMang/heap_4.o ./freertos/freertos_kernel/portable/GCC/ARM_CM4F/port.o ./freertos/freertos_kernel/croutine.o ./freertos/freertos_kernel/event_groups.o ./freertos/freertos_kernel/list.o ./freertos/freertos_kernel/queue.o ./freertos/freertos_kernel/stream_buffer.o ./freertos/freertos_kernel/tasks.o ./freertos/freertos_kernel/timers.o ./drivers/fsl_clock.o ./drivers/fsl_common.o ./drivers/fsl_flexcomm.o ./drivers/fsl_gpio.o ./drivers/fsl_reset.o ./drivers/fsl_usart.o ./device/system_LPC54114_cm4.o ./component/uart/fsl_adapter_usart.o ./component/serial_manager/fsl_component_serial_manager.o ./component/serial_manager/fsl_component_serial_port_uart.o ./component/lists/fsl_component_generic_list.o ./board/board.o ./board/clock_config.o ./board/pin_mux.o ./LPC54114/drivers/fsl_power.o -lpower_cm4_hardabi
c:/nxp/mcuxpressoide_11.5.1_7266/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.5.1.202201181444/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: warning: cannot find entry symbol _start; defaulting to 00008000
c:/nxp/mcuxpressoide_11.5.1_7266/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.5.1.202201181444/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: ./utilities/fsl_debug_console.o: in function `DbgConsole_Init':
C:\Users\iotlab0035\Documents\MCUXpressoIDE_11.5.1_7266\workspace\lpcxpresso54114_freertos_hello\Debug/../utilities/fsl_debug_console.c:821: undefined reference to `memset'
c:/nxp/mcuxpressoide_11.5.1_7266/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.5.1.202201181444/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: ./utilities/fsl_debug_console.o: in function `DbgConsole_Printf':
C:\Users\iotlab0035\Documents\MCUXpressoIDE_11.5.1_7266\workspace\lpcxpresso54114_freertos_hello\Debug/../utilities/fsl_debug_console.c:975: undefined reference to `memset'
c:/nxp/mcuxpressoide_11.5.1_7266/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.5.1.202201181444/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: ./utilities/fsl_debug_console.o: in function `DbgConsole_BlockingPrintf':
C:\Users\iotlab0035\Documents\MCUXpressoIDE_11.5.1_7266\workspace\lpcxpresso54114_freertos_hello\Debug/../utilities/fsl_debug_console.c:1021: undefined reference to `memset'
c:/nxp/mcuxpressoide_11.5.1_7266/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.5.1.202201181444/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: ./utilities/fsl_str.o: in function `StrFormatPrintf':
C:\Users\iotlab0035\Documents\MCUXpressoIDE_11.5.1_7266\workspace\lpcxpresso54114_freertos_hello\Debug/../utilities/fsl_str.c:930: undefined reference to `strlen'
c:/nxp/mcuxpressoide_11.5.1_7266/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.5.1.202201181444/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: ./utilities/fsl_str.o: in function `StrFormatScanfStringHandling':
C:\Users\iotlab0035\Documents\MCUXpressoIDE_11.5.1_7266\workspace\lpcxpresso54114_freertos_hello\Debug/../utilities/fsl_str.c:1240: undefined reference to `strtoul'
c:/nxp/mcuxpressoide_11.5.1_7266/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.5.1.202201181444/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\iotlab0035\Documents\MCUXpressoIDE_11.5.1_7266\workspace\lpcxpresso54114_freertos_hello\Debug/../utilities/fsl_str.c:1313: undefined reference to `errno'
c:/nxp/mcuxpressoide_11.5.1_7266/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.5.1.202201181444/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: ./utilities/fsl_str.o: in function `StrFormatScanf':
C:\Users\iotlab0035\Documents\MCUXpressoIDE_11.5.1_7266\workspace\lpcxpresso54114_freertos_hello\Debug/../utilities/fsl_str.c:1487: undefined reference to `strlen'
c:/nxp/mcuxpressoide_11.5.1_7266/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.5.1.202201181444/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\iotlab0035\Documents\MCUXpressoIDE_11.5.1_7266\workspace\lpcxpresso54114_freertos_hello\Debug/../utilities/fsl_str.c:1491: undefined reference to `memcpy'
c:/nxp/mcuxpressoide_11.5.1_7266/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.5.1.202201181444/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\iotlab0035\Documents\MCUXpressoIDE_11.5.1_7266\workspace\lpcxpresso54114_freertos_hello\Debug/../utilities/fsl_str.c:1494: undefined reference to `strtoul'
c:/nxp/mcuxpressoide_11.5.1_7266/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.5.1.202201181444/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\iotlab0035\Documents\MCUXpressoIDE_11.5.1_7266\workspace\lpcxpresso54114_freertos_hello\Debug/../utilities/fsl_str.c:1506: undefined reference to `strtoul'
c:/nxp/mcuxpressoide_11.5.1_7266/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.5.1.202201181444/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\iotlab0035\Documents\MCUXpressoIDE_11.5.1_7266\workspace\lpcxpresso54114_freertos_hello\Debug/../utilities/fsl_str.c:1550: undefined reference to `errno'
c:/nxp/mcuxpressoide_11.5.1_7266/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.5.1.202201181444/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: ./startup/startup_lpc5411x.o:C:\Users\iotlab0035\Documents\MCUXpressoIDE_11.5.1_7266\workspace\lpcxpresso54114_freertos_hello\Debug/../startup/startup_lpc5411x.c:240: undefined reference to `_vStackTop'
c:/nxp/mcuxpressoide_11.5.1_7266/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.5.1.202201181444/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: ./startup/startup_lpc5411x.o: in function `ResetISR':
C:\Users\iotlab0035\Documents\MCUXpressoIDE_11.5.1_7266\workspace\lpcxpresso54114_freertos_hello\Debug/../startup/startup_lpc5411x.c:535: undefined reference to `__main'
c:/nxp/mcuxpressoide_11.5.1_7266/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.5.1.202201181444/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\iotlab0035\Documents\MCUXpressoIDE_11.5.1_7266\workspace\lpcxpresso54114_freertos_hello\Debug/../startup/startup_lpc5411x.c:535: undefined reference to `__data_section_table'
c:/nxp/mcuxpressoide_11.5.1_7266/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.5.1.202201181444/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\iotlab0035\Documents\MCUXpressoIDE_11.5.1_7266\workspace\lpcxpresso54114_freertos_hello\Debug/../startup/startup_lpc5411x.c:535: undefined reference to `__data_section_table_end'
c:/nxp/mcuxpressoide_11.5.1_7266/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.5.1.202201181444/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\iotlab0035\Documents\MCUXpressoIDE_11.5.1_7266\workspace\lpcxpresso54114_freertos_hello\Debug/../startup/startup_lpc5411x.c:535: undefined reference to `__bss_section_table_end'
c:/nxp/mcuxpressoide_11.5.1_7266/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.5.1.202201181444/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: ./freertos/freertos_kernel/queue.o: in function `prvCopyDataToQueue':
C:\Users\iotlab0035\Documents\MCUXpressoIDE_11.5.1_7266\workspace\lpcxpresso54114_freertos_hello\Debug/../freertos/freertos_kernel/queue.c:2104: undefined reference to `memcpy'
c:/nxp/mcuxpressoide_11.5.1_7266/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.5.1.202201181444/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\iotlab0035\Documents\MCUXpressoIDE_11.5.1_7266\workspace\lpcxpresso54114_freertos_hello\Debug/../freertos/freertos_kernel/queue.c:2117: undefined reference to `memcpy'
c:/nxp/mcuxpressoide_11.5.1_7266/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.5.1.202201181444/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: ./freertos/freertos_kernel/queue.o: in function `prvCopyDataFromQueue':
C:\Users\iotlab0035\Documents\MCUXpressoIDE_11.5.1_7266\workspace\lpcxpresso54114_freertos_hello\Debug/../freertos/freertos_kernel/queue.c:2168: undefined reference to `memcpy'
c:/nxp/mcuxpressoide_11.5.1_7266/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.5.1.202201181444/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: ./freertos/freertos_kernel/stream_buffer.o: in function `vStreamBufferDelete':
C:\Users\iotlab0035\Documents\MCUXpressoIDE_11.5.1_7266\workspace\lpcxpresso54114_freertos_hello\Debug/../freertos/freertos_kernel/stream_buffer.c:387: undefined reference to `memset'
c:/nxp/mcuxpressoide_11.5.1_7266/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.5.1.202201181444/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: ./freertos/freertos_kernel/stream_buffer.o: in function `prvWriteBytesToBuffer':
C:\Users\iotlab0035\Documents\MCUXpressoIDE_11.5.1_7266\workspace\lpcxpresso54114_freertos_hello\Debug/../freertos/freertos_kernel/stream_buffer.c:1103: undefined reference to `memcpy'
c:/nxp/mcuxpressoide_11.5.1_7266/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.5.1.202201181444/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\iotlab0035\Documents\MCUXpressoIDE_11.5.1_7266\workspace\lpcxpresso54114_freertos_hello\Debug/../freertos/freertos_kernel/stream_buffer.c:1111: undefined reference to `memcpy'
c:/nxp/mcuxpressoide_11.5.1_7266/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.5.1.202201181444/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: ./freertos/freertos_kernel/stream_buffer.o: in function `prvReadBytesFromBuffer':
C:\Users\iotlab0035\Documents\MCUXpressoIDE_11.5.1_7266\workspace\lpcxpresso54114_freertos_hello\Debug/../freertos/freertos_kernel/stream_buffer.c:1154: undefined reference to `memcpy'
c:/nxp/mcuxpressoide_11.5.1_7266/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.5.1.202201181444/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\iotlab0035\Documents\MCUXpressoIDE_11.5.1_7266\workspace\lpcxpresso54114_freertos_hello\Debug/../freertos/freertos_kernel/stream_buffer.c:1162: undefined reference to `memcpy'
c:/nxp/mcuxpressoide_11.5.1_7266/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.5.1.202201181444/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: ./freertos/freertos_kernel/stream_buffer.o: in function `prvInitialiseNewStreamBuffer':
C:\Users\iotlab0035\Documents\MCUXpressoIDE_11.5.1_7266\workspace\lpcxpresso54114_freertos_hello\Debug/../freertos/freertos_kernel/stream_buffer.c:1224: undefined reference to `memset'
c:/nxp/mcuxpressoide_11.5.1_7266/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.5.1.202201181444/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\iotlab0035\Documents\MCUXpressoIDE_11.5.1_7266\workspace\lpcxpresso54114_freertos_hello\Debug/../freertos/freertos_kernel/stream_buffer.c:1228: undefined reference to `memset'
c:/nxp/mcuxpressoide_11.5.1_7266/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.5.1.202201181444/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: ./freertos/freertos_kernel/tasks.o: in function `prvInitialiseNewTask':
C:\Users\iotlab0035\Documents\MCUXpressoIDE_11.5.1_7266\workspace\lpcxpresso54114_freertos_hello\Debug/../freertos/freertos_kernel/tasks.c:854: undefined reference to `memset'
c:/nxp/mcuxpressoide_11.5.1_7266/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.5.1.202201181444/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: ./drivers/fsl_clock.o: in function `CLOCK_SetFRGClock':
C:\Users\iotlab0035\Documents\MCUXpressoIDE_11.5.1_7266\workspace\lpcxpresso54114_freertos_hello\Debug/../drivers/fsl_clock.c:579: undefined reference to `__aeabi_uldivmod'
c:/nxp/mcuxpressoide_11.5.1_7266/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.5.1.202201181444/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: ./drivers/fsl_clock.o: in function `CLOCK_GetFrgClkFreq':
C:\Users\iotlab0035\Documents\MCUXpressoIDE_11.5.1_7266\workspace\lpcxpresso54114_freertos_hello\Debug/../drivers/fsl_clock.c:595: undefined reference to `__aeabi_uldivmod'
c:/nxp/mcuxpressoide_11.5.1_7266/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.5.1.202201181444/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: ./drivers/fsl_clock.o: in function `CLOCK_GetPllConfigInternal':
C:\Users\iotlab0035\Documents\MCUXpressoIDE_11.5.1_7266\workspace\lpcxpresso54114_freertos_hello\Debug/../drivers/fsl_clock.c:1201: undefined reference to `__aeabi_uldivmod'
c:/nxp/mcuxpressoide_11.5.1_7266/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.5.1.202201181444/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\iotlab0035\Documents\MCUXpressoIDE_11.5.1_7266\workspace\lpcxpresso54114_freertos_hello\Debug/../drivers/fsl_clock.c:1201: undefined reference to `__aeabi_uldivmod'
c:/nxp/mcuxpressoide_11.5.1_7266/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.5.1.202201181444/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: ./drivers/fsl_clock.o: in function `CLOCK_GetSystemPLLOutFromSetup':
C:\Users\iotlab0035\Documents\MCUXpressoIDE_11.5.1_7266\workspace\lpcxpresso54114_freertos_hello\Debug/../drivers/fsl_clock.c:1400: undefined reference to `__aeabi_uldivmod'
c:/nxp/mcuxpressoide_11.5.1_7266/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.5.1.202201181444/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: ./drivers/fsl_common.o: in function `SDK_Malloc':
C:\Users\iotlab0035\Documents\MCUXpressoIDE_11.5.1_7266\workspace\lpcxpresso54114_freertos_hello\Debug/../drivers/fsl_common.c:152: undefined reference to `malloc'
c:/nxp/mcuxpressoide_11.5.1_7266/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.5.1.202201181444/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: ./drivers/fsl_common.o: in function `SDK_Free':
C:\Users\iotlab0035\Documents\MCUXpressoIDE_11.5.1_7266\workspace\lpcxpresso54114_freertos_hello\Debug/../drivers/fsl_common.c:185: undefined reference to `free'
c:/nxp/mcuxpressoide_11.5.1_7266/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.5.1.202201181444/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: ./drivers/fsl_common.o: in function `SDK_DelayAtLeastUs':
C:\Users\iotlab0035\Documents\MCUXpressoIDE_11.5.1_7266\workspace\lpcxpresso54114_freertos_hello\Debug/../drivers/fsl_common.c:275: undefined reference to `__aeabi_uldivmod'
c:/nxp/mcuxpressoide_11.5.1_7266/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.5.1.202201181444/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: ./drivers/fsl_usart.o: in function `USART_GetDefaultConfig':
C:\Users\iotlab0035\Documents\MCUXpressoIDE_11.5.1_7266\workspace\lpcxpresso54114_freertos_hello\Debug/../drivers/fsl_usart.c:307: undefined reference to `memset'
c:/nxp/mcuxpressoide_11.5.1_7266/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.5.1.202201181444/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: ./drivers/fsl_usart.o: in function `USART_TransferCreateHandle':
C:\Users\iotlab0035\Documents\MCUXpressoIDE_11.5.1_7266\workspace\lpcxpresso54114_freertos_hello\Debug/../drivers/fsl_usart.c:685: undefined reference to `memset'
c:/nxp/mcuxpressoide_11.5.1_7266/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.5.1.202201181444/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: ./device/system_LPC54114_cm4.o: in function `SystemCoreClockUpdate':
C:\Users\iotlab0035\Documents\MCUXpressoIDE_11.5.1_7266\workspace\lpcxpresso54114_freertos_hello\Debug/../device/system_LPC54114_cm4.c:345: undefined reference to `__aeabi_uldivmod'
c:/nxp/mcuxpressoide_11.5.1_7266/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.5.1.202201181444/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: ./component/serial_manager/fsl_component_serial_manager.o: in function `SerialManager_Init':
C:\Users\iotlab0035\Documents\MCUXpressoIDE_11.5.1_7266\workspace\lpcxpresso54114_freertos_hello\Debug/../component/serial_manager/fsl_component_serial_manager.c:1092: undefined reference to `memset'
c:/nxp/mcuxpressoide_11.5.1_7266/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.5.1.202201181444/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: ./component/serial_manager/fsl_component_serial_manager.o: in function `SerialManager_OpenWriteHandle':
C:\Users\iotlab0035\Documents\MCUXpressoIDE_11.5.1_7266\workspace\lpcxpresso54114_freertos_hello\Debug/../component/serial_manager/fsl_component_serial_manager.c:1309: undefined reference to `memset'
c:/nxp/mcuxpressoide_11.5.1_7266/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.5.1.202201181444/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: ./component/serial_manager/fsl_component_serial_manager.o: in function `SerialManager_CloseWriteHandle':
C:\Users\iotlab0035\Documents\MCUXpressoIDE_11.5.1_7266\workspace\lpcxpresso54114_freertos_hello\Debug/../component/serial_manager/fsl_component_serial_manager.c:1347: undefined reference to `memset'
c:/nxp/mcuxpressoide_11.5.1_7266/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.5.1.202201181444/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: ./component/serial_manager/fsl_component_serial_manager.o: in function `SerialManager_OpenReadHandle':
C:\Users\iotlab0035\Documents\MCUXpressoIDE_11.5.1_7266\workspace\lpcxpresso54114_freertos_hello\Debug/../component/serial_manager/fsl_component_serial_manager.c:1381: undefined reference to `memset'
c:/nxp/mcuxpressoide_11.5.1_7266/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.5.1.202201181444/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: ./component/serial_manager/fsl_component_serial_manager.o: in function `SerialManager_CloseReadHandle':
C:\Users\iotlab0035\Documents\MCUXpressoIDE_11.5.1_7266\workspace\lpcxpresso54114_freertos_hello\Debug/../component/serial_manager/fsl_component_serial_manager.c:1416: undefined reference to `memset'
c:/nxp/mcuxpressoide_11.5.1_7266/ide/plugins/com.nxp.mcuxpresso.tools.win32_11.5.1.202201181444/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\iotlab0035\Documents\MCUXpressoIDE_11.5.1_7266\workspace\lpcxpresso54114_freertos_hello\LPC54114\mcuxpresso\libpower_cm4_hardabi.a(fsl_power_lib.o): in function `POWER_EnterDeepSleep':
D:/02-work/git repo/mcu-sdk-2.0/devices/LPC54114/fsl_power_lib/fsl_power_lib.c:423: undefined reference to `memcpy'
collect2.exe: error: ld returned 1 exit status
make[1]: *** [makefile:74: lpcxpresso54114_freertos_hello.axf] Error 1
make: *** [makefile:65: all] Error 2
"make -r -j8 all" terminated with exit code 2. Build might be incomplete.

09:59:35 Build Failed. 76 errors, 1 warnings. (took 1s.502ms)

0 Kudos

5,047 Views
frank_m
Senior Contributor III

> I did as you suggested but I had this error after clean build: ...

> Invoking: MCU C++ Linker
> arm-none-eabi-c++ -nostdlib - ...

The missing symbols are in the stdlib. I would try adding "-lc".

 

0 Kudos

5,023 Views
misterbee
Contributor II

I am new to MCUXpresso, could you tell me where and how to add this 'lc'?

0 Kudos

5,014 Views
frank_m
Senior Contributor III

This is more an Eclipse thing than a MCUXpresso thing.

Right-click on the project in the "Workspace" tab, select "Properties", and add it here:

frank_meyer_0-1654580546135.png

And, you can play with this settings:

frank_meyer_1-1654580681023.png

 

I don't use MCUXpresso very much, to be honest.

0 Kudos

1,727 Views
GanesanGuru
Contributor IV

Hi @frank_m 

Can you explain it further - as I can't get it.Let'me explain where I'm stuck.

I've converted project into C/C++ like this and I checked MCU C++ Libraries for the include files/search paths, its completely empty as attached below img..

Screenshot from 2023-11-08 15-21-57.png

 

Also, the uploadd img is blury and hence can't understant which links to be added in Include path. Kindly, let me asap, as I'm stuck there..

0 Kudos

1,520 Views
frank_m
Senior Contributor III

Sorry, but I can't help you with that.
I don't have much experience with converting projects from C to C++, which proved troublesome with all IDEs I ever worked with. And Eclipse especially.

Perhaps the author of the linked article could help you.
Mind you, it is already 3 years old, Eclipse/LPCXpresso versions have changed, and thus it might not be up to date anymore.

 

As a side note, NXP's email verification was a mess. It took me about a dozen attempts until the NXP verification mail arrived _before_ the link expired.

0 Kudos

4,950 Views
misterbee
Contributor II

Thanks @frank_m , unfortunately I still don't get it. What toolchain you use and recommend then ?

0 Kudos

4,947 Views
frank_m
Senior Contributor III

For private projects, I use mostly Segger Embedded Studio now. Runs on Linux, and supports multiple vendors. At one point I got tired of installing another 1GB vendor-specific toolchain just for one board.

At work I use the stuff my company bought.

I recommend the tool you are familiar with, and that does the job.

0 Kudos

5,144 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello

Recommend you use declare this function as "extern C" as well. as Frank said.

 

0 Kudos

5,142 Views
misterbee
Contributor II

Hi @Alice_Yang ,

I did it but not helping.

 

Anyway, I decided to abandon using MCUXpresso IDE, was frustrated over this simple thing.

I used GNU Toolchains and it works well without changing the code side.

0 Kudos

5,171 Views
misterbee
Contributor II

From the build log, I  confirmed that the .cpp file was not even compiled. What should I do to include it into the build?

0 Kudos

5,171 Views
misterbee
Contributor II

It seems the issue is the .cpp file that I added was not automatically included in the build. So this .cpp was not even compiled and therefore linking error. Is there anything I should do to ensure this .cpp part of the build?

0 Kudos

5,180 Views
frank_m
Senior Contributor III

First, I can see no need to declare the "App.cpp" source as C++, so renaming it to *.c would be the simplest solution.

Second, C++ implies name-mangling, which is required for the overloading feature of C++. My C++ is a bit rusty, but a solution is to declare this function as "extern C" as well.

But third, C++ cources and C projects don't work well together. Not only is the linking stage generally different, C++ requires and uses different startup code as well.

Better create a C++ project to begin with.

0 Kudos

5,177 Views
misterbee
Contributor II

Thanks @fra ,

  1. I still need to declare as cpp as in there I plan to instantiate a class. I just made a simple example to demonstrate my intention.

2.  There is need to declare the function as extern "C" as this is already taken care by :

 

#ifdef __cplusplus
extern "C" {
#endif

#ifdef __cplusplus
}
#endif

 

 

3. C and C++ works together as historically C++ was continuity from C. And I know this can work as I use the same approach on another project before, using IAR on STM32 platform.

 

I still want to have C project, as I plan to write lower level code in C. But for application logic I plan to write in C++. There is gotta be a way.

0 Kudos

5,168 Views
frank_m
Senior Contributor III

> 3. C and C++ works together as historically C++ was continuity from C. And I know this can work as I use the same approach on another project before, using IAR on STM32 platform.

But not both ways.

A C++ project can 'include' and deal with plain C files, but the reverse is not true. Some PC-based toolchains did support such an approach in a limited fashion, but no embedded toolchain I know of.

As mentioned, C++ requires special linker support and a special startup. Classes require constructors and destructors (check your startup code for CTOR and DTOR symbols ...).

Obviously, your toolchain does not even recognice files not named *.c/*.h in C mode.

As said, create a C++ project, and add your C files to that project.

0 Kudos

5,166 Views
misterbee
Contributor II

" but the reverse is not true"

Actually still true, I have been using this way on another project. Also, I used the same code in GNU arm toolchain and it works.

"As said, create a C++ project, and add your C files to that project"

This is not what I want. Also there is no SDK sample that I want in C++. It is all in C.

 

0 Kudos

2,708 Views
shivangi_23
Contributor I
Spoiler
 

So, Have you found any solution in using cpp files in c projects

0 Kudos