undefined reference to `printf' or puts under arm-none-eabi-gcc-6.2.1

Asked by shengyang

I want to build my projetc with stm32F7 code under linux use arm-none-eabi tools.Now i can build simpile project with led under Linux and success.But when i test usart mode,and use printf function with stdio.h head file.My source printf("yyfish nihao zhonguo") is just simple.
I get the err about yyfish.c:(.text.startup+0x38): undefined reference to `printf'.I try to define int __io_putchar(int ch) or int _write (int fd, const void *buf, size_t count),then i get the same error .But when I change this code as printf("yyfish nihao zhonguo\r\n");I get error as below
yyfish.c:(.text.startup+0x66): undefined reference to `puts'
and I add LDFLAGS=-L /usr/local/arm/gcc-arm-none-eabi-6_2-2016q4/arm-none-eabi/lib/thumb/v7e-m -l c -L /usr/local/arm/gcc-arm-none-eabi-6_2-2016q4/lib/gcc/arm-none-eabi/6.2.1/thumb/v7e-m -l gcc
but it's useless,what‘s wrong maybe???

Question information

Language:
English Edit question
Status:
Solved
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Solved by:
Thomas Preud'homme
Solved:
Last query:
Last reply:
Revision history for this message
Tejas Belagod (belagod-tejas) said :
#1

Hi,

You dont need to explicitly add the libs paths to the LD cmdline... the compiler driver knows where to pick the multilibs from depending on the options given.

Can you try:

$ arm-none-eabi-gcc -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -specs=rdimon.specs yyfish.c -o yyfish.out

and see if that cmd line works for you?

Thanks,
Tejas.

Revision history for this message
shengyang (shengyang) said :
#2

I'm sorry to reply you so late,I just go back my home for china new year festival yesterday,
[sheng@red stm32F7]$ make > log.txt
/home/sheng/Samba/redProject/stm32F7/usr_src/yyfish.o: In function `main':
yyfish.c:(.text.startup+0x66): undefined reference to `puts'
As you can see, I still get this message when I try to ld these obj files to a target,my log is as below:

 arm-none-eabi-gcc -mcpu=cortex-m7 -c -O2 -I/home/sheng/Samba/redProject/stm32F7/hal_inc -I/home/sheng/Samba/redProject/stm3 2F7/usr_inc -I/home/sheng/Samba/redProject/stm32F7/core_inc -specs=rdimon.specs -Wa,-mthumb -mfloat-abi=hard -mfpu=fpv5-d16 /home/sheng/Samba/redProject/stm32F7/usr_src/yyfish.c -o /home/sheng/Samba/redProject/stm32F7/usr_src/yyfish.o
I can get yyfish.o usccess.

But i failed to get yyfish as below:
arm-none-eabi-ld -Bstatic -T STM32F767IGT_ITCM_FLASH.ld --gc-sections -L /usr/local/arm/gcc-arm-none-eabi-6_2-2016q4/arm-non e-eabi/lib/thumb/v7e-m -l c -L /usr/local/arm/gcc-arm-none-eabi-6_2-2016q4/lib/gcc/arm-none-eabi/6.2.1/thumb/v7e-m -l gcc - Ttext 0x08002000 --gc-sections /home/sheng/Samba/redProject/stm32F7/core_src/startup_stm32f767xx.o /home/sheng/Samba/redPro ject/stm32F7/core_src/system_stm32f7xx.o /home/sheng/Samba/redProject/stm32F7/usr_src/yyfish.o /home/sheng/Samba/redProject/ stm32F7/hal_src/stm32f7xx_hal.o /home/sheng/Samba/redProject/stm32F7/hal_src/stm32f7xx_hal_cortex.o /home/sheng/Samba/redPro ject/stm32F7/hal_src/stm32f7xx_hal_dma.o /home/sheng/Samba/redProject/stm32F7/hal_src/stm32f7xx_hal_rcc.o /home/sheng/Samba/ redProject/stm32F7/hal_src/stm32f7xx_hal_gpio.o /home/sheng/Samba/redProject/stm32F7/hal_src/stm32f7xx_hal_uart.o -o yyfish

failed log:
/home/sheng/Samba/redProject/stm32F7/usr_src/yyfish.o: In function `main':
yyfish.c:(.text.startup+0x66): undefined reference to `puts'
As you can see, I still get this message when I try to ld these obj files to a target,my log is as below:

Revision history for this message
Tejas Belagod (belagod-tejas) said :
#3

Try:

 $ arm-none-eabi-gcc -mcpu=cortex-m7 --specs=rdimon.specs -mthumb -mfloat-abi=hard -mfpu=fpv5-d16 -Wl,-Ttext 0x08002000 -Wl,--gc-sections /home/sheng/Samba/redProject/stm32F7/core_src/startup_stm32f767xx.o /home/sheng/Samba/redPro ject/stm32F7/core_src/system_stm32f7xx.o /home/sheng/Samba/redProject/stm32F7/usr_src/yyfish.o /home/sheng/Samba/redProject/ stm32F7/hal_src/stm32f7xx_hal.o /home/sheng/Samba/redProject/stm32F7/hal_src/stm32f7xx_hal_cortex.o /home/sheng/Samba/redPro ject/stm32F7/hal_src/stm32f7xx_hal_dma.o /home/sheng/Samba/redProject/stm32F7/hal_src/stm32f7xx_hal_rcc.o /home/sheng/Samba/ redProject/stm32F7/hal_src/stm32f7xx_hal_gpio.o /home/sheng/Samba/redProject/stm32F7/hal_src/stm32f7xx_hal_uart.o -o yyfish

Revision history for this message
shengyang (shengyang) said :
#4

I need use STM32F767IGT_ITCM_FLASH.ld ld scripts file to generate the obj file.How could I use STM32F767IGT_ITCM_FLASH.ld file in your answer?

Revision history for this message
Thomas Preud'homme (thomas-preudhomme) said :
#5

Hi Shengyang,

Just add -T /path/to/STM32F767IGT_ITCM_FLASH.ld to the ld part of the command-line where /path/to/ is replace by the path to that ld script. So something like:

$ arm-none-eabi-gcc -mcpu=cortex-m7 --specs=rdimon.specs -mthumb -mfloat-abi=hard -mfpu=fpv5-d16 -Wl,-Ttext 0x08002000 -Wl,--gc-sections -Wl,-T,/path/to/STM32F767IGT_ITCM_FLASH.ld /home/sheng/Samba/redProject/stm32F7/core_src/startup_stm32f767xx.o /home/sheng/Samba/redPro ject/stm32F7/core_src/system_stm32f7xx.o /home/sheng/Samba/redProject/stm32F7/usr_src/yyfish.o /home/sheng/Samba/redProject/ stm32F7/hal_src/stm32f7xx_hal.o /home/sheng/Samba/redProject/stm32F7/hal_src/stm32f7xx_hal_cortex.o /home/sheng/Samba/redPro ject/stm32F7/hal_src/stm32f7xx_hal_dma.o /home/sheng/Samba/redProject/stm32F7/hal_src/stm32f7xx_hal_rcc.o /home/sheng/Samba/ redProject/stm32F7/hal_src/stm32f7xx_hal_gpio.o /home/sheng/Samba/redProject/stm32F7/hal_src/stm32f7xx_hal_uart.o -o yyfish

Best regards

Revision history for this message
shengyang (shengyang) said :
#6

As your device,I can use gcc to link these object files success,but i still couldn't use printf function success on my embedded board with cortex-m7 chip.I define _write function use HAL function as below
int _write (int fd, const void *buf, size_t count)
{
  (void)fd;
  HAL_UART_Transmit(&UartHandle, (uint8_t *)buf, count, 0xFFFF);
  return count;
}
when I invoke printf function ,I couldn't see uart port data send.But if i invoke HAL_UART_Transmit func directly,I can see data transmit on my PC.

Revision history for this message
Launchpad Janitor (janitor) said :
#7

This question was expired because it remained in the 'Open' state without activity for the last 15 days.

Revision history for this message
shengyang (shengyang) said :
#8

I hope could reopen my problem.

发自网易邮箱手机版

在2018年03月06日 16:47,Launchpad Janitor 写道:
Your question #662420 on GNU Arm Embedded Toolchain changed:
https://answers.launchpad.net/gcc-arm-embedded/+question/662420

   Status: Open => Expired

Launchpad Janitor expired the question:
This question was expired because it remained in the 'Open' state
without activity for the last 15 days.

--
If you're still having this problem, you can reopen your question either
by replying to this email or by going to the following page and
entering more information about your problem:
https://answers.launchpad.net/gcc-arm-embedded/+question/662420

You received this question notification because you asked the question.

Revision history for this message
Best Thomas Preud'homme (thomas-preudhomme) said :
#9

If you want retargeting (ie your own _write to be called), then you should link with -specs=nosys.specs instead of -specs=rdimon.specs.

Best regards,

Thomas

Revision history for this message
shengyang (shengyang) said :
#10

Thanks Thomas Preud'homme, that solved my question.