GCC ARM linker错误-未定义的“strcmp”引用

时间:2022-09-01 05:37:39

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. 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. My makefile switches:

我有一个TIVA-C单片机项目,它是用arm-none-eabi-gcc编译的,虽然我添加了字符串。我对strcmp的链接错误有一个未定义的引用。我正在使用预编译的工具链:gcc-arm-none-eabi-4_8-2014q3-20140805-linux.tar。bz2从这里获取:https://launchpad.net/gcc-arm-embedded/ +下载。我的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. I'm out of ideas now, so any tip would be great.

还有一些人也有同样的问题,但他们在LDFLAGS上有一个-绞股蓝开关我显然没有。我现在没主意了,所以任何小费都可以。

2 个解决方案

#1


4  

The problem happens because you use -ld for linking directly. As a multilib toolchain, arm-none-eabi has multiple variants of libc.a (which contains the function you need) and other standard libraries. -ld just cannot find the right libraries.

问题发生是因为您使用-ld直接链接。作为一个多*度的工具链,arm-none-eabi有多种不同的libc变体。a(包含您需要的函数)和其他标准库。找不到合适的图书馆。

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. No prefix is needed for -T, -L and -l.

这个想法很简单——对于链接阶段,您可以通过所有与体系结构相关的选项(所有以-m开头的选项),并且链接器的选项都是由- wl前缀的,多个链接器选项可以用逗号连接,而不需要重复- wl,前缀。-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. 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项目,其中包括一个相当不错的Makefile——我从来没有遇到过这样的库问题。在我的网站上(link in profile),去下载> ARM >的例子,然后选择你喜欢的一个——没有tiva的例子,但是STM32F4的版本是最接近的。

#2


1  

As you're using an embedded toolchain, it likely doesn't link to libc without you instructing it to. add -lc to your LDFLAGS to see if it solves the problem as this will at least attempt to link to libc.

当您使用嵌入式工具链时,它可能与libc无关,而不需要您指示它。将-lc添加到您的LDFLAGS中,看看它是否解决了这个问题,因为这至少会尝试链接到libc。

#1


4  

The problem happens because you use -ld for linking directly. As a multilib toolchain, arm-none-eabi has multiple variants of libc.a (which contains the function you need) and other standard libraries. -ld just cannot find the right libraries.

问题发生是因为您使用-ld直接链接。作为一个多*度的工具链,arm-none-eabi有多种不同的libc变体。a(包含您需要的函数)和其他标准库。找不到合适的图书馆。

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. No prefix is needed for -T, -L and -l.

这个想法很简单——对于链接阶段,您可以通过所有与体系结构相关的选项(所有以-m开头的选项),并且链接器的选项都是由- wl前缀的,多个链接器选项可以用逗号连接,而不需要重复- wl,前缀。-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. 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项目,其中包括一个相当不错的Makefile——我从来没有遇到过这样的库问题。在我的网站上(link in profile),去下载> ARM >的例子,然后选择你喜欢的一个——没有tiva的例子,但是STM32F4的版本是最接近的。

#2


1  

As you're using an embedded toolchain, it likely doesn't link to libc without you instructing it to. add -lc to your LDFLAGS to see if it solves the problem as this will at least attempt to link to libc.

当您使用嵌入式工具链时,它可能与libc无关,而不需要您指示它。将-lc添加到您的LDFLAGS中,看看它是否解决了这个问题,因为这至少会尝试链接到libc。