1

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:

# 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.

10
  • can you please show us the error message? Commented Nov 27, 2014 at 13:17
  • Give a test. Add just a reference to strcmp (Just declare the prototype of the function), and try to compile again. I want to check if the shared object of the libc will be dynamically linked. If not, then the standard C library is not correctly installed for your arm crosscompilation Commented Nov 27, 2014 at 13:18
  • me@sg:~/__PW__/projecttiva$ make arm-none-eabi-ld -o build/a.out build/console.o build/cmdline.o build/uartstdio.o build/startup_gcc.o build/console_uart.o build/console_command.o build/board.o build/main.o -T TM4C123GH6PM.ld --entry ResetISR --gc-sections build/cmdline.o: In function CmdLineProcess': /home/me/__PW__/projecttiva/src/cmdline.c:169: undefined reference to strcmp' make: *** [build/a.out] Error 1 Commented Nov 27, 2014 at 13:19
  • @sestus: I commented out string.h and put int strcmp(const char * s1, const char * s2); on the top of the relevant source file. I've got the same error message. (I hope I interpreted your question correctly). Commented Nov 27, 2014 at 13:26
  • Yes that was what I meant. To me it seems that the linker cannot locate the libc shared object (for arm). Are you sure you installed it? Commented Nov 27, 2014 at 13:31

2 Answers 2

6

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.

To solve your problem, modify your makefile in following places:

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.

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.

Sign up to request clarification or add additional context in comments.

8 Comments

Freddie thank you for the detailed answer. I can compile&link my code now. Probably you mean LD = arm-none-eabi-gcc instead of LD = arm-none-eabi-g++, don't you? Anyways, I changed to that and the compiler/linker did not complain.
@JustGreg - You can use gcc or g++ for linking - it doesn't matter.
Also, just a stylistic note, it's perhaps cleaner to read with newline escapes rather than repeatedly appending to CFLAGS.
@OllieFord - pure preference, I like += more (;
@FreddieChopin Woah, okay. :)
|
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.