0

我用 gcc-6.2 构建了一个包含所有最新组件的工具链。

CC      = arm-none-eabi-gcc
AS      = arm-none-eabi-as
LD      = arm-none-eabi-ld

我的 Makefile 标志是:

CFLAGS = -std=c11 -Wall -Werror -Wfatal-errors -Wstrict-prototypes -Wundef -gdwarf-2 -O2 -mthumb -mthumb-interwork -mcpu=cortex-m7 -mfloat-abi=softfp -mfpu=fpv4-sp-d16 -mlittle-endian

LDFLAGS = -nodefaultlibs -T./STM32F746NGHx_FLASH.ld -Wl,-Map=ugui3.map,--cref

我通过编译器进行链接。CFLAGS 前部和 LDFLAGS 后部:

Linking: ugui3.elf
arm-none-eabi-gcc -std=c11 -Wall -Werror -Wfatal-errors -Wstrict prototypes -Wundef -gdwarf-2 -O2 -mthumb -mthumb-interwork -mcpu=cortex-m7 -mfloat-abi=softfp -mfpu=fpv4-sp-d16 -mlittle-endian stm32746g_discovery.o stm32746g_discovery_lcd.o stm32746g_discovery_sdram.o stm32746g_discovery_ts.o system_stm32f7xx.o stm32f7xx_hal.o stm32f7xx_hal_cortex.o stm32f7xx_hal_dma.o stm32f7xx_hal_dma2d.o stm32f7xx_hal_dma_ex.o stm32f7xx_hal_gpio.o stm32f7xx_hal_i2c.o stm32f7xx_hal_i2c_ex.o stm32f7xx_hal_ltdc.o stm32f7xx_hal_pwr.o stm32f7xx_hal_pwr_ex.o stm32f7xx_hal_rcc.o stm32f7xx_hal_rcc_ex.o stm32f7xx_hal_sdram.o stm32f7xx_hal_uart.o stm32f7xx_ll_fmc.o stm32f7xx_hal_msp.o stm32f7xx_it.o main.o ugui.o ltdc.o sdram.o ft5336.o small_printf.o startup_stm32f746xx.o --output ugui3.elf -nodefaultlibs -T./STM32F746NGHx_FLASH.ld -Wl,-Map=ugui3.map,--cref

我可以将 CFLAGS 中的内容简化为: CFLAGS = -mthumb -mthumb-interwork

Linking: ugui3.elf
arm-none-eabi-gcc -mthumb -mthumb-interwork -mcpu=cortex-m7 -mfloat-abi=softfp -mfpu=fpv4-sp-d16 -mlittle-endian stm32746g_discovery.o stm32746g_discovery_lcd.o stm32746g_discovery_sdram.o stm32746g_discovery_ts.o system_stm32f7xx.o stm32f7xx_hal.o stm32f7xx_hal_cortex.o stm32f7xx_hal_dma.o stm32f7xx_hal_dma2d.o stm32f7xx_hal_dma_ex.o stm32f7xx_hal_gpio.o stm32f7xx_hal_i2c.o stm32f7xx_hal_i2c_ex.o stm32f7xx_hal_ltdc.o stm32f7xx_hal_pwr.o stm32f7xx_hal_pwr_ex.o stm32f7xx_hal_rcc.o stm32f7xx_hal_rcc_ex.o stm32f7xx_hal_sdram.o stm32f7xx_hal_uart.o stm32f7xx_ll_fmc.o stm32f7xx_hal_msp.o stm32f7xx_it.o main.o ugui.o ltdc.o sdram.o ft5336.o small_printf.o startup_stm32f746xx.o --output ugui3.elf -nodefaultlibs -T./STM32F746NGHx_FLASH.ld -Wl,-Map=ugui3.map,--cref

我的问题:

  1. 是否首选通过编译器调用链接器(如上所示)?

  2. 第一种方法比第二种方法好吗?有没有更好的办法?

4

1 回答 1

0

我迁移到其他几个项目并继续研究这个。

A:
arm-none-eabi-gcc -mthumb < .o files > --output image.elf -T./lpc1768.ld -nostartfiles -Wl,-Map=image.map,--cref

B:
arm-none-eabi-gcc < .o files > --output image.elf -T./lpc1768.ld -nostartfiles -Wl,-Map=image.map,--cref -L /usr/local/arm-none-eabi/lib/thumb

A 和 B 都有效。带有“-mthumb”的方法 A 假定您要链接到 libc.a 的 thumb 版本。方法 B 将 thumb 版本指定为 -L /usr/local/arm-none-eabi/lib/thumb

在另一个项目中,我可以在链接上使用最少的一行,没有 -mthumb 标志,也没有库路径。

C:
arm-none-eabi-gcc < .o files > --output image.elf -T./lpc2132.ld -nostartfiles -Wl,-Map=image.map,--cref

方法 C 适用于 lpc2132(arm7tdmi-s) 项目。但方法 C 不适用于 lpc1768(Cortex-m3) 项目 (A & B)。它们具有几乎相同的 .ld 文件和启动文件。

方法 C 不起作用(没有显式库或路径)的原因是 ARM 库默认链接。由于 lpc1768 是一个只有拇指的处理器,这并不好。需要“-mthumb”或“-L 拇指库路径”。

于 2016-12-31T15:34:44.840 回答