简体   繁体   English

GCC ARM链接器错误-未定义对'strcmp'的引用

[英]GCC ARM linker error - undefined reference to 'strcmp'

I have a TIVA-C microcontroller project, compiled with arm-none-eabi-gcc and although I added string.h I'm getting 'undefined reference to strcmp' linker error. 我有一个TIVA-C微控制器项目,该项目使用arm-none-eabi-gcc进行了编译,尽管我添加了string.h,但是却收到“未定义对strcmp的引用”链接器错误。 I'm using the precompiled toolchain: gcc-arm-none-eabi-4_8-2014q3-20140805-linux.tar.bz2 from here: https://launchpad.net/gcc-arm-embedded/+download . 我正在使用预编译的工具链:gcc-arm-none-eabi-4_8-2014q3-20140805-linux.tar.bz2从这里: https ://launchpad.net/gcc-arm-embedded/+download。 My makefile switches: 我的makefile切换:

# define flags
CFLAGS = -g -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=softfp
CFLAGS +=-Os -ffunction-sections -fdata-sections -MD -std=c99 -Wall
CFLAGS += -pedantic -DPART_$(MCU) -c -I$(TIVAWARE_PATH)
CFLAGS += -DTARGET_IS_BLIZZARD_RA1
LDFLAGS = -T $(LD_SCRIPT) --entry ResetISR --gc-sections

There were others with the same problem but they've the -nostd switch on in the LDFLAGS what I apparently don't have. 还有其他人也有同样的问题,但是他们在LDFLAGS中打开了-nostd,而我显然没有。 I'm out of ideas now, so any tip would be great. 我现在没主意了,所以任何提示都会很棒。

The problem happens because you use -ld for linking directly. 发生问题是因为您使用-ld直接链接。 As a multilib toolchain, arm-none-eabi has multiple variants of libc.a (which contains the function you need) and other standard libraries. 作为多库工具链,arm-none-eabi具有libc.a(包含所需功能)和其他标准库的多个变体。 -ld just cannot find the right libraries. -ld只是找不到正确的库。

To solve your problem, modify your makefile in following places: 要解决您的问题,请在以下位置修改makefile:

Replace: 更换:

# define flags
CFLAGS = -g -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=softfp
CFLAGS +=-Os -ffunction-sections -fdata-sections -MD -std=c99 -Wall
CFLAGS += -pedantic -DPART_$(MCU) -c -I$(TIVAWARE_PATH)
CFLAGS += -DTARGET_IS_BLIZZARD_RA1
LDFLAGS = -T $(LD_SCRIPT) --entry ResetISR --gc-sections

with: 与:

# define flags
COREFLAGS = -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=softfp
CFLAGS = -g $(COREFLAGS)
CFLAGS +=-Os -ffunction-sections -fdata-sections -MD -std=c99 -Wall
CFLAGS += -pedantic -DPART_$(MCU) -c -I$(TIVAWARE_PATH)
CFLAGS += -DTARGET_IS_BLIZZARD_RA1
LDFLAGS = $(COREFLAGS) -T$(LD_SCRIPT) -Wl,--entry=ResetISR,--gc-sections

Replace: 更换:

LD = arm-none-eabi-ld

with: 与:

LD = arm-none-eabi-g++

The idea is simple - to the linking stage you pass all the options that are relevant to the architecture (everything that starts with -m ), and the options for linker are prefixed with -Wl, , multiple linker options can be concatenated with commas, without the need to repeat the -Wl, prefix. 这个想法很简单-在链接阶段,您传递与架构相关的所有选项(所有以-m开头的选项),并且链接器选项以-Wl,开头,多个链接器选项可以用逗号连接,无需重复-Wl,前缀。 No prefix is needed for -T , -L and -l . -T-L-l不需要前缀。

You can also check out my example ARM projects, which include a quite nice Makefile - I never had any library issues with that. 您也可以查看我的示例ARM项目,其中包括一个非常不错的Makefile-我从没有任何库问题。 On my website (link in profile) go to Download > ARM > Examples, and pick which one you like - there's no example for tiva, but the one for STM32F4 will be the closest match. 在我的网站上(配置文件中的链接),转到下载> ARM>示例,然后选择您喜欢的一个-没有tiva的示例,但是STM32F4的是最接近的示例。

As you're using an embedded toolchain, it likely doesn't link to libc without you instructing it to. 当您使用嵌入式工具链时,如果没有您的指示,它可能不会链接到libc。 add -lc to your LDFLAGS to see if it solves the problem as this will at least attempt to link to libc. 在您的LDFLAGS中添加-lc ,以查看它是否可以解决问题,因为这至少会尝试链接到libc。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM