undefined reference

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

undefined reference

6,668 Views
stefan_ivanov
Contributor I

I am working with MCUXpresso IDE and a project for IMXRT1052B MCU.

After Build phase I am receiving many messages "undefined reference".

0 Kudos
29 Replies

3,542 Views
lpcxpresso_supp
NXP Employee
NXP Employee

So have you tried as previously suggested ...  start a second instance of the IDE using a different workspace and use the New project wizard to create a new C++ project for your device. Check that this builds correctly. Then compare and contrast the project settings, and the tool invocations on the Build log in the console view between your project and the new project just created.

We certainly see no issue building C++ projects here.

Regards,

MCUXpresso IDE Support

0 Kudos

3,542 Views
stefan_ivanov
Contributor I

Yes, I 've tried. The result is the same. I am porting a project for an old ARM 920T for a new ARM Cortex M7. The code si a mix of C and

C++ code. But the project I've configured naturally as a C++ project.

0 Kudos

3,542 Views
lpcxpresso_supp
NXP Employee
NXP Employee

Have you modified the contents of the IDE installation directory at all?

I would suggest that you start a second instance of the IDE using a different workspace and use the New project wizard to create a new C++ project for your device. Check that this builds correctly. Then compare and contrast the project settings, and the tool invocations on the Build log in the console view between your project and the new project just created.

Regards,

MCUXpresso IDE Support

0 Kudos

3,542 Views
stefan_ivanov
Contributor I

I have not modified contents of IDE installation directory at all.

The project is C++, but the code is mix of C and C++ code.

I am porting software from ARM 920T to ARM Cortex M7 and

FreeRTOS.

Regards,

Stefan Ivanov

0 Kudos

3,560 Views
lpcxpresso_supp
NXP Employee
NXP Employee

So that sounds like you may actually have a C rather than a C++ project ? Do you see the MCU C++ Compiler in the "Tool Settings" tab of your Project Settings?

Regards,

MCUXpresso IDE Support

0 Kudos

3,560 Views
stefan_ivanov
Contributor I

I have C++ project.

The latest issue is:

Invoking: MCU C++ Linker
arm-none-eabi-c++ -nostdlib -L"C:/nxp/MCUXpressoIDE_10.2.0_759/ide/tools/arm-none-eabi/bin/" -L"C:/nxp/MCUXpressoIDE_10.2.0_759/ide/tools/lib/gcc/arm-none-eabi/7.2.1/" -L"C:/nxp/MCUXpressoIDE_10.2.0_759/ide/tools/arm-none-eabi/lib/" -specs=nosys.specs -Xlinker -Map="IRIS_IMXRT1052B.map" -Xlinker --gc-sections -Xlinker -print-memory-usage -Xlinker --sort-section=alignment -Xlinker -specs=nano.specs -mcpu=cortex-m7 -mfpu=fpv5-sp-d16 -mfloat-abi=hard -mthumb -T IRIS_IMXRT1052B_Release.ld -o "IRIS_IMXRT1052B.axf"  ./startup/startup_mimxrt1052.o  ./source/IRIS_IMXRT1052B.o ./source/semihost_hardfault.o  ./lwip-1.1.1/src/netif/ppp/auth.o ./lwip-1.1.1/src/netif/ppp/chap.o ./lwip-1.1.1/src/netif/ppp/chpms.o ./lwip-1.1.1/src/netif/ppp/fsm.o ./lwip-1.1.1/src/netif/ppp/ipcp.o ./lwip-1.1.1/src/netif/ppp/lcp.o ./lwip-1.1.1/src/netif/ppp/magic.o ./lwip-1.1.1/src/netif/ppp/md5.o ./lwip-1.1.1/src/netif/ppp/pap.o ./lwip-1.1.1/src/netif/ppp/ppp.o ./lwip-1.1.1/src/netif/ppp/randm.o ./lwip-1.1.1/src/netif/ppp/vj.o  ./lwip-1.1.1/src/netif/etharp.o ./lwip-1.1.1/src/netif/ethernetif.o ./lwip-1.1.1/src/netif/loopif.o ./lwip-1.1.1/src/netif/slipif.o  ./lwip-1.1.1/src/core/ipv4/icmp.o ./lwip-1.1.1/src/core/ipv4/ip.o ./lwip-1.1.1/src/core/ipv4/ip_addr.o ./lwip-1.1.1/src/core/ipv4/ip_frag.o  ./lwip-1.1.1/src/core/dhcp.o ./lwip-1.1.1/src/core/inet.o ./lwip-1.1.1/src/core/mem.o ./lwip-1.1.1/src/core/memp.o ./lwip-1.1.1/src/core/netif.o ./lwip-1.1.1/src/core/pbuf.o ./lwip-1.1.1/src/core/raw.o ./lwip-1.1.1/src/core/stats.o ./lwip-1.1.1/src/core/sys.o ./lwip-1.1.1/src/core/tcp.o ./lwip-1.1.1/src/core/tcp_in.o ./lwip-1.1.1/src/core/tcp_out.o ./lwip-1.1.1/src/core/udp.o  ./lwip-1.1.1/src/api/api_lib.o ./lwip-1.1.1/src/api/api_msg.o ./lwip-1.1.1/src/api/err.o ./lwip-1.1.1/src/api/sockets.o ./lwip-1.1.1/src/api/tcpip.o  ./lwip-1.1.1/src/lwIP_main.o  ./lwip-1.1.1/contrib/port/FreeRTOS/CS8900/sys_arch.o  ./board/board.o ./board/clock_config.o ./board/peripherals.o ./board/pin_mux.o  ./amazon-freertos/portable/fsl_tickless_systick.o ./amazon-freertos/portable/heap_4.o  ./amazon-freertos/FreeRTOS/portable/port.o  ./amazon-freertos/FreeRTOS/event_groups.o ./amazon-freertos/FreeRTOS/list.o ./amazon-freertos/FreeRTOS/queue.o ./amazon-freertos/FreeRTOS/stream_buffer.o ./amazon-freertos/FreeRTOS/tasks.o ./amazon-freertos/FreeRTOS/timers.o  ./Periphery/Usb/AMDFlash.o ./Periphery/Usb/M29W160EB_x16_x2.o ./Periphery/Usb/USB.o ./Periphery/Usb/USB_Functions.o ./Periphery/Usb/progflash.o ./Periphery/Usb/usb_descriptors.o ./Periphery/Usb/usbrx.o  ./Periphery/Uart/uart1.o ./Periphery/Uart/uart2.o ./Periphery/Uart/uart3.o  ./Periphery/Timers/timers.o  ./Periphery/Spi/fs.o ./Periphery/Spi/spi_flash.o  ./Periphery/Sound/sound.o  ./Periphery/Rtc/rtc.o  ./Periphery/Log/log.o  ./Periphery/Led/led.o  ./Periphery/FAT_FBF/FAT_FBF.o  ./Periphery/Communicator/communicator.o  ./Periphery/CRC/crc32.o  ./Periphery/periphery_devices.o ./Periphery/periphery_manager.o ./Periphery/test_input.o  ./ModBus/ModBus.o ./ModBus/ModBusCrc.o  ./Main/AFP.o ./Main/NetMsg.o ./Main/Network.o ./Main/NetworkMem.o ./Main/RamManager.o ./Main/UDLManager.o ./Main/init.o ./Main/init_rom.o ./Main/init_rom_to_ram.o ./Main/int_handler.o ./Main/vectors_rom.o  ./LCD/TouchScreen/calibrate.o ./LCD/TouchScreen/lcd_touch.o ./LCD/TouchScreen/touchscreen.o  ./LCD/Menus/Zones/lcd_zones.o  ./LCD/Menus/Time/lcd_time.o ./LCD/Menus/Time/lcd_time_images.o ./LCD/Menus/Time/lcd_time_menu.o  ./LCD/Menus/Test/lcd_menu_test.o  ./LCD/Menus/System/lcd_menu_system.o  ./LCD/Menus/Save/lcd_save.o  ./LCD/Menus/PeripheryDevices/lcd_periphery_devices.o  ./LCD/Menus/Network/LanMessagingSystem.o ./LCD/Menus/Network/Lcd_IP_Table.o ./LCD/Menus/Network/Lcd_Network.o  ./LCD/Menus/MainMenu/lcd_Menu_Main.o  ./LCD/Menus/LoopDevices/lcd_loop_devices.o  ./LCD/Menus/Kbd/lcd_kbd.o ./LCD/Menus/Kbd/lcd_kbd_images.o ./LCD/Menus/Kbd/lcd_txt_fields_images.o  ./LCD/Menus/IO/lcd_io.o ./LCD/Menus/IO/lcd_io_images.o  ./LCD/Menus/Disable/lcd_menu_disable.o  ./LCD/Menus/Communicator/lcd_communicator.o ./LCD/Menus/Communicator/lcd_mod_communicator.o  ./LCD/Menus/Calibration/lcd_calibration.o  ./LCD/Menus/Alarms/alarms_txt_images.o ./LCD/Menus/Alarms/lcd_alarm_images.o ./LCD/Menus/Alarms/lcd_alarms.o  ./LCD/Menus/AccessCodes/lcd_access_codes.o  ./LCD/Main/LCD_Test.o ./LCD/Main/lcd.o ./LCD/Main/lcd_SSA.o ./LCD/Main/lcd_globals.o ./LCD/Main/lcd_messages.o ./LCD/Main/lcd_misc.o ./LCD/Main/lcd_modes.o ./LCD/Main/lcd_objects.o  ./LCD/Lcd_Strings/lcd_strings.o  ./LCD/Lcd_Spi/lcd_spi.o  ./LCD/Lcd_Rtc/lcd_RTC.o  ./LCD/Lcd_Images/IMAGES.o ./LCD/Lcd_Images/lcd_image_Base_Grey.o ./LCD/Lcd_Images/lcd_image_Base_Normal.o ./LCD/Lcd_Images/lcd_images_definitions.o ./LCD/Lcd_Images/status_background.o  ./LCD/Lcd_Icons/lcd_icon_images.o ./LCD/Lcd_Icons/lcd_icons.o  ./LCD/Lcd_Fonts/font12x8_Bold.o ./LCD/Lcd_Fonts/font12x8_Normal.o ./LCD/Lcd_Fonts/font16x16Bold.o ./LCD/Lcd_Fonts/font16x16Normal.o ./LCD/Lcd_Fonts/fontANSII.o ./LCD/Lcd_Fonts/lcd_fonts.o  ./LCD/Lcd_Control/lcd_control.o  ./LCD/Lcd_Color_Palletes/lcd_RGB.o  ./LCD/Extras/Farsi.o ./LCD/Extras/lcd_ScreenSaver.o  ./Headers/utility.o  ./Fire/IO.o ./Fire/SaveConfig.o ./Fire/access_codes.o ./Fire/fire.o ./Fire/loop_device.o ./Fire/message_type_txt.o ./Fire/zone.o  ./CMSIS/system_MIMXRT1052.o  ./BasicWEB.o   -llibgcc.a -llibc_nano.a -llibstdc++_nano.a -llibm.a -llibcr_newlib_none.a
c:/nxp/mcuxpressoide_10.2.0_759/ide/tools/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/bin/ld.exe: cannot find -llibgcc.a
c:/nxp/mcuxpressoide_10.2.0_759/ide/tools/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/bin/ld.exe: cannot find -llibc_nano.a
c:/nxp/mcuxpressoide_10.2.0_759/ide/tools/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/bin/ld.exe: cannot find -llibstdc++_nano.a
c:/nxp/mcuxpressoide_10.2.0_759/ide/tools/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/bin/ld.exe: cannot find -llibm.a
c:/nxp/mcuxpressoide_10.2.0_759/ide/tools/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/bin/ld.exe: cannot find -llibcr_newlib_none.a
collect2.exe: error: ld returned 1 exit status

I tried may be everything, but...nothing...

I really do not know what to do ?!

Regards,

Stefan Ivanov

0 Kudos

3,559 Views
converse
Senior Contributor V

You appear to have added the following libraries to the linker command line (either under Miscellaneous, or with Libraries - I can't tell which!)

-llibgcc.a -llibc_nano.a -llibstdc++_nano.a -llibm.a -llibcr_newlib_none.a

Remove all of them - the IDE automatically adds the correct C++ libraries in the Managed Linker script.

BTW: If you want to add libraries to the command line, you must remove the leading "lib" and the trailing ".a", so if you did want to add libraries yourself, you would add them like this

-lgcc -lc_nano -lstdc++_nano -lm -lcr_newlib_none

BUT (as I said) none of these are needed, as the IDE adds them automatically.

0 Kudos

3,560 Views
stefan_ivanov
Contributor I

The result is:

-many messages "undefined references to..." +

C:/nxp/MCUXpressoIDE_10.2.0_759/ide/tools/arm-none-eabi/lib/\libc_nano.a(lib_a-abort.o): In function `abort':
abort.c:(.text.abort+0x10): undefined reference to `_exit'
C:/nxp/MCUXpressoIDE_10.2.0_759/ide/tools/arm-none-eabi/lib/\libc_nano.a(lib_a-signalr.o): In function `_kill_r':
signalr.c:(.text._kill_r+0x1c): undefined reference to `_kill'
C:/nxp/MCUXpressoIDE_10.2.0_759/ide/tools/arm-none-eabi/lib/\libc_nano.a(lib_a-signalr.o): In function `_getpid_r':
signalr.c:(.text._getpid_r+0x4): undefined reference to `_getpid'
collect2.exe: error: ld returned 1 exit status
        SRAM_DTC:          0 GB       128 KB      0.00%
make: *** [IRIS_IMXRT1052B.axf] Error 1

0 Kudos

3,559 Views
converse
Senior Contributor V

Suggest you read this:

https://community.nxp.com/thread/389070 

0 Kudos

3,559 Views
stefan_ivanov
Contributor I

Yes, I have read this. I have changed library from NewlibNano(none) to NewlibNano(semihost).

Messages undefined reference to `_exit'undefined reference to `_kill'undefined reference to `_getpid'

disappeared, there are messages  "undefined references to...". I have tried many things, but... nothing.

0 Kudos

3,559 Views
converse
Senior Contributor V

What are the current errors?

0 Kudos

3,559 Views
stefan_ivanov
Contributor I

Many messages  "undefined reference to..."

0 Kudos

3,548 Views
converse
Senior Contributor V

Your going to have to tell us what references are undefined.

0 Kudos

3,541 Views
stefan_ivanov
Contributor I

Here there is a small excerpt in the end of console.

I've tried many things, searched in .net and s.o.

I have no more ideas...

……………………………………………………………………………………………………………………………………………………………………….

./LCD/Lcd_Icons/lcd_icons.o: In function `f_UpdateCounters(unsigned short)':
D:\Projects\IRIS_IMXRT1052B\Release/../LCD/Lcd_Icons/lcd_icons.cpp:152: undefined reference to `f_UnsignedShortToUniCode(unsigned short, unsigned short*, int, bool, unsigned char)'
D:\Projects\IRIS_IMXRT1052B\Release/../LCD/Lcd_Icons/lcd_icons.cpp:185: undefined reference to `f_UnsignedShortToUniCode(unsigned short, unsigned short*, int, bool, unsigned char)'
D:\Projects\IRIS_IMXRT1052B\Release/../LCD/Lcd_Icons/lcd_icons.cpp:218: undefined reference to `f_UnsignedShortToUniCode(unsigned short, unsigned short*, int, bool, unsigned char)'
./LCD/Lcd_Icons/lcd_icons.o: In function `f_UpdateInfoIcon_SND(unsigned short)':
D:\Projects\IRIS_IMXRT1052B\Release/../LCD/Lcd_Icons/lcd_icons.cpp:287: undefined reference to `f_UnsignedShortToUniCode(unsigned short, unsigned short*, int, bool, unsigned char)'
./LCD/Lcd_Icons/lcd_icons.o: In function `f_UpdateInfoIcon_FB(unsigned short)':
D:\Projects\IRIS_IMXRT1052B\Release/../LCD/Lcd_Icons/lcd_icons.cpp:365: undefined reference to `f_UnsignedShortToUniCode(unsigned short, unsigned short*, int, bool, unsigned char)'
./LCD/Lcd_Icons/lcd_icons.o:D:\Projects\IRIS_IMXRT1052B\Release/../LCD/Lcd_Icons/lcd_icons.cpp:441: more undefined references to `f_UnsignedShortToUniCode(unsigned short, unsigned short*, int, bool, unsigned char)' follow
collect2.exe: error: ld returned 1 exit status
        SRAM_DTC:          0 GB       128 KB      0.00%
make: *** [IRIS_IMXRT1052B.axf] Error 1

0 Kudos

3,542 Views
converse
Senior Contributor V

You need to supply a library that provides those functions - they are not provided by C, C++ or any standard library shipped with MCUXpresso

0 Kudos

3,542 Views
stefan_ivanov
Contributor I

For these functions there are definitions as well as included header files and so on. 

0 Kudos

3,542 Views
converse
Senior Contributor V

Sorry, but unless you provide your project, I am unable to help any further.

0 Kudos

3,542 Views
stefan_ivanov
Contributor I

The code is proprietary.

It turned out that the only way to link code without any errors is to check "Shared" !?

0 Kudos

3,560 Views
lpcxpresso_supp
NXP Employee
NXP Employee

My best guess is that your project is not actually linking with the C++ library archives.  Section 15.7 "Libraries and linker scripts" of the MCUXpresso IDE v10.2 User Guide covers the libraries that would generally be expected to be linked against for different project types / library settings.

Check this information agains the linker script files (.ld) from inside your project.

[ And are you using managed linker scripts - or is your project perhaps configured to use a manual linker script? ]

Regards,

MCUXpresso IDE Support

0 Kudos

3,560 Views
stefan_ivanov
Contributor I

I am using managed linker scripts but despite of that I have added C++ libraries

libgcc.a libc_nano.a libstdc++_nano.a libm.a libcr_newlib_none.a 

and... everything is O'K !

Thanks a lot !

0 Kudos