使用Arm GNU Toolchain编译C++文件到ARM Cortex-M4(TM4C123GXL)目标时出现链接错误求助
Arm GNU Toolchain编译C++文件到ARM Cortex-M4(TM4C123GXL)目标时出现链接错误求助
我现在正尝试用GNU工具链为ARM Cortex-M4目标(具体是TM4C123GXL开发板)编译C++文件,用的是官方SDK里的闪烁灯示例程序。
如果用arm-none-eabi-gcc编译原版C语言的blinky.c,整个编译和链接过程都很顺利,用到的命令如下:
arm-none-eabi-gcc -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -ffunction-sections -fdata-sections -MD -std=c99 -Wall -pedantic -DPART_TM4C123GH6PM -c -Os -DTARGET_IS_TM4C123_RB1 -fno-builtin -I../../../.. -Dgcc -o gcc/blinky.o blinky.c arm-none-eabi-gcc -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -ffunction-sections -fdata-sections -MD -std=c99 -Wall -pedantic -DPART_TM4C123GH6PM -c -Os -DTARGET_IS_TM4C123_RB1 -fno-builtin -I../../../.. -Dgcc -o gcc/startup_gcc.o startup_gcc.c arm-none-eabi-ld -T blinky.ld --entry ResetISR --gc-sections -o gcc/blinky.axf gcc/blinky.o gcc/startup_gcc.o ../../../../driverlib/gcc/libdriver.a /Applications/ArmGNUToolchain/13.3.rel1/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard/libm.a /Applications/ArmGNUToolchain/13.3.rel1/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard/libc.a /Applications/ArmGNUToolchain/13.3.rel1/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard/libstdc++.a /Applications/ArmGNUToolchain/13.3.rel1/arm-none-eabi/lib/gcc/arm-none-eabi/13.3.1/thumb/v7e-m+fp/hard/libgcc.a
但当我把blinky.c改名为blinky.cc,改用arm-none-eabi-g++编译这个C++版本的文件时,链接阶段就报错了。我用的编译链接命令如下:
arm-none-eabi-g++ -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -ffunction-sections -fdata-sections -MD -std=c99 -Wall -pedantic -DPART_TM4C123GH6PM -c -Os -DTARGET_IS_TM4C123_RB1 -fno-builtin -I../../../.. -fno-builtin -I../../../.. -o gcc/blinky.o blinky.cc arm-none-eabi-gcc -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -ffunction-sections -fdata-sections -MD -Wall -pedantic -DPART_TM4C123GH6PM -c -Os -DTARGET_IS_TM4C123_RB1 -fno-builtin -I../../../.. -Dgcc -o gcc/startup_gcc.o startup_gcc.c arm-none-eabi-ld -T blinky.ld --entry ResetISR --gc-sections -o gcc/blinky.axf gcc/blinky.o gcc/startup_gcc.o ../../../../driverlib/gcc/libdriver.a /Applications/ArmGNUToolchain/13.3.rel1/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard/libm.a /Applications/ArmGNUToolchain/13.3.rel1/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard/libc.a /Applications/ArmGNUToolchain/13.3.rel1/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard/libstdc++.a /Applications/ArmGNUToolchain/13.3.rel1/arm-none-eabi/lib/gcc/arm-none-eabi/13.3.1/thumb/v7e-m+fp/hard/libgcc.a
具体的错误信息如下:
arm-none-eabi-ld: /Applications/ArmGNUToolchain/13.3.rel1/arm-none-eabi/lib/gcc/arm-none-eabi/13.3.1/thumb/v7e-m+fp/hard/libgcc.a(unwind-arm.o): in function `get_eit_entry': unwind-arm.c:(.text.get_eit_entry+0x90): undefined reference to `__exidx_start' arm-none-eabi-ld: unwind-arm.c:(.text.get_eit_entry+0x94): undefined reference to `__exidx_end' arm-none-eabi-ld: /Applications/ArmGNUToolchain/13.3.rel1/arm-none-eabi/lib/gcc/arm-none-eabi/13.3.1/thumb/v7e-m+fp/hard/libgcc.a(unwind-arm.o): in function `unwind_phase2': unwind-arm.c:(.text.unwind_phase2+0x36): undefined reference to `abort' arm-none-eabi-ld: /Applications/ArmGNUToolchain/13.3.rel1/arm-none-eabi/lib/gcc/arm-none-eabi/13.3.1/thumb/v7e-m+fp/hard/libgcc.a(unwind-arm.o): in function `unwind_phase2_forced': unwind-arm.c:(.text.unwind_phase2_forced+0x4a): undefined reference to `memcpy' arm-none-eabi-ld: unwind-arm.c:(.text.unwind_phase2_forced+0x78): undefined reference to `memcpy' arm-none-eabi-ld: /Applications/ArmGNUToolchain/13.3.rel1/arm-none-eabi/lib/gcc/arm-none-eabi/13.3.1/thumb/v7e-m+fp/hard/libgcc.a(unwind-arm.o): in function `__gnu_Unwind_Resume': unwind-arm.c:(.text.__gnu_Unwind_Resume+0x3c): undefined reference to `abort' arm-none-eabi-ld: unwind-arm.c:(.text.__gnu_Unwind_Resume+0x40): undefined reference to `abort' ../../../../makedefs:244: recipe for target 'gcc/blinky.axf' failed gmake: *** [gcc/blinky.axf] Error 1
我实在搞不懂为什么只是把文件改成C后缀,用g编译就会出现这些链接错误,希望有大佬能帮我分析一下原因,或者给出解决办法。
备注:内容来源于stack exchange,提问作者Akash Modi
相关产品推荐
相关产品推荐

