arm-none-eabi-g++ 编译问题的解决

在使用GCC7.3.0编译支持C++17特性的代码并移植到TI3352芯片时遇到链接错误,错误涉及undefinedreferenceto__sync_synchronize。问题源于缺少对CPU类型的指定。通过在编译和链接过程中添加-mcpu=cortex-a8-mtune=cortex-a8-march=armv7-a参数,以及--specs=nosys.specs解决了该问题,最终成功生成BIN文件。编译过程中还需注意变量大小对齐的警告。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近需要使用gcc编译一个C++的算法库,移植到TI 3352的芯片上,GCC版本为7.3.0,支持C++17特性,编译过程没有问题,但是编译完后进行.o链接生成Bin文件的时候,出现下列报错:

arm-none-eabi-g++ --specs=nosys.specs obj/main.o obj/position-step1.o obj/velocity-step2.o obj/velocity-step1.o obj/position-step2.o obj/brake.o -o bin/main
c:/xmc/160/gcc/bin/../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/lib\libstdc++.a(locale.o): In function `std::locale::_Impl::_M_install_cache(std::locale::facet const*, unsigned int)':
locale.cc:(.text._ZNSt6locale5_Impl16_M_install_cacheEPKNS_5facetEj+0x18): undefined reference to `__sync_synchronize'
c:/xmc/160/gcc/bin/../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/lib\libstdc++.a(cxx11-ios_failure.o): In function `(anonymous namespace)::__io_category_instance()':
cxx11-ios_failure.cc:(.text._ZN12_GLOBAL__N_122__io_category_instanceEv+0xc): undefined reference to `__sync_synchronize'
c:/xmc/160/gcc/bin/../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/lib\libstdc++.a(locale_init.o): In function `(anonymous namespace)::get_locale_mutex()':
locale_init.cc:(.text._ZN12_GLOBAL__N_116get_locale_mutexEv+0xc): undefined reference to `__sync_synchronize'
collect2.exe: error: ld returned 1 exit status
make: *** [makefile:22: bin/main] Error 1

主要问题出在这里:undefined reference to `__sync_synchronize'。

最后网上搜寻资料,找到原因为:arm-noe-babi编译过程需要指定CPU类型,如下

CFLAGS = -g -std=c++17  -Wall -I ${DIR_INC} -Os -flto -ffunction-sections -fdata-sections -mthumb -mabi=aapcs-linux -fstack-usage -mcpu=cortex-a8 -mtune=cortex-a8 -march=armv7-a
CXXFLAGS=$(CFLAGS)

因为我编译的时候指定的了处理器类型 -mcpu=cortex-a8 -mtune=cortex-a8 -march=armv7-a

所以链接的过程也需要指定处理器类型

#目标文件main,依赖/obj下的所有.o文件
${BIN_TARGET}:${OBJ}
    $(CC) --specs=nosys.specs -mcpu=cortex-a8 -mtune=cortex-a8 -march=armv7-a $^ -o $@

--specs=nosys.specs要加上,不然会报undefined reference to _exit()的错误。

最后用make命令编译,成功输出BIN文件

arm-none-eabi-g++ --specs=nosys.specs -mcpu=cortex-a8 -mtune=cortex-a8 -march=armv7-a obj/main.o obj/position-step1.o obj/velocity-step2.o obj/velocity-step1.o obj/position-step2.o obj/brake.o -o bin/main
c:/xmc/160/gcc/bin/../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/bin/ld.exe: warning: C:\Users\ADMINI~1\AppData\Local\Temp\ccuah5CG.ltrans0.ltrans.o uses 32-bit enums yet the output is to use variable-size enums; use of enum values across objects may fail
c:/xmc/160/gcc/bin/../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/bin/ld.exe: warning: C:\Users\ADMINI~1\AppData\Local\Temp\ccuah5CG.ltrans1.ltrans.o uses 32-bit enums yet the output is to use variable-size enums; use of enum values across objects may fail
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值