使用 GNU MCU Eclipse 插件的 Eclipse 中 arm-none-eabi 链接器的问题

Problems with arm-none-eabi linker in Eclipse using GNU MCU Eclipse Plugin

我在尝试为我的新 STM32F7 Nucleo 开发板设置的项目时遇到问题。我刚刚安装了 GNU ARM Embedded toolchain, STM32CubeF7 and the GNU MCU Eclipse Plugin,我用它在我工作的 Windows 7 机器上设置了一个新项目。我以前在家里用我的 Ubuntu 笔记本电脑做过,没有问题。 设置项目后,我添加了 HAL 和 CMSIS 库,并使用了来自 STM32CubeF7 的模板项目。到目前为止,编译工作正常,但在链接时出现以下错误:

c:/program files (x86)/gnu tools arm embedded/5.4 2016q2/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/bin/ld.exe: cannot find -lc_p-lc_p

据我了解,这里的问题是无法找到某些名称非常奇怪的库。不幸的是,唯一的 page that I found where the same error is described 是俄语,我根本不会说。

乍一看,生成的 makefile 似乎已损坏,并且试图链接一个名为 c_p 的库,但它完成了两次,中间没有 space。所以这可能是 Eclipse 或 Eclipse GNU MCU 插件的问题。

我试图消除错误的事情:

这是自动生成的 makefile:

################################################################################
# Automatically-generated file. Do not edit!
################################################################################

-include ../makefile.init

RM := rm -rf

# All of the sources participating in the build are defined here
-include sources.mk
-include system/src/subdir.mk
-include system/HAL/Src/subdir.mk
-include system/subdir.mk
-include src/subdir.mk
-include subdir.mk
-include objects.mk

ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(CC_DEPS)),)
-include $(CC_DEPS)
endif
ifneq ($(strip $(C++_DEPS)),)
-include $(C++_DEPS)
endif
ifneq ($(strip $(C_UPPER_DEPS)),)
-include $(C_UPPER_DEPS)
endif
ifneq ($(strip $(CXX_DEPS)),)
-include $(CXX_DEPS)
endif
ifneq ($(strip $(ASM_DEPS)),)
-include $(ASM_DEPS)
endif
ifneq ($(strip $(S_UPPER_DEPS)),)
-include $(S_UPPER_DEPS)
endif
ifneq ($(strip $(C_DEPS)),)
-include $(C_DEPS)
endif
ifneq ($(strip $(CPP_DEPS)),)
-include $(CPP_DEPS)
endif
endif

-include ../makefile.defs

# Add inputs and outputs from these tool invocations to the build variables 
SECONDARY_FLASH += \
stm32Template.hex \

SECONDARY_SIZE += \
stm32Template.siz \


# All Target
all: stm32Template.elf secondary-outputs

# Tool invocations
stm32Template.elf: $(OBJS) $(USER_OBJS)
    @echo 'Building target: $@'
    @echo 'Invoking: GNU ARM Cross C++ Linker'
    arm-none-eabi-g++ -mcpu=cortex-m7 -mthumb -mfloat-abi=soft -O0 -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -ffreestanding -fno-move-loop-invariants -Wall -Wextra  -g3 -p -pg -T mem.ld -T libs.ld -T sections.ld -nostartfiles -L"../ldscripts" -Wl,-Map,"stm32Template.map" --specs=nano.specs -o "stm32Template.elf" $(OBJS) $(USER_OBJS) $(LIBS)
    @echo 'Finished building target: $@'
    @echo ' '

stm32Template.hex: stm32Template.elf
    @echo 'Invoking: GNU ARM Cross Create Flash Image'
    arm-none-eabi-objcopy -O ihex "stm32Template.elf"  "stm32Template.hex"
    @echo 'Finished building: $@'
    @echo ' '

stm32Template.siz: stm32Template.elf
    @echo 'Invoking: GNU ARM Cross Print Size'
    arm-none-eabi-size --format=berkeley "stm32Template.elf"
    @echo 'Finished building: $@'
    @echo ' '

# Other Targets
clean:
    -$(RM) $(CC_DEPS)$(C++_DEPS)$(OBJS)$(C_UPPER_DEPS)$(CXX_DEPS)$(SECONDARY_FLASH)$(SECONDARY_SIZE)$(ASM_DEPS)$(S_UPPER_DEPS)$(C_DEPS)$(CPP_DEPS) stm32Template.elf
    -@echo ' '

secondary-outputs: $(SECONDARY_FLASH) $(SECONDARY_SIZE)

.PHONY: all clean dependents

-include ../makefile.targets

有人对此有任何意见吗?

编辑: GNU MCU Eclipse Plugin 为新项目提供了一个模板,即使这样我也会得到同样的错误。

你犯了一个非常重要的错误。您尝试使用 DIY Eclipse 配置导入为特定环境创建的项目。

安装 OpenSTM32。 使用 SW4STM32 工具链设置生成您的项目。

导入项目。编译、link 和调试

如果您发现安装的工具链已过时,您将能够替换它。

一段时间后我想出了解决这个问题的方法,但不幸的是我还没有找到它的确切原因。我搜索了我的 GNU ARM Embedded toolchain 安装文件夹,但没有找到任何包含 c_p 的库名称。我想这个问题的原因一定是链接器的默认库被定义的地方,这就是为什么我认为问题出在工具链本身。

但是,我选择禁用默认库(-nodefaultlibs 标志)并自己链接它们。我链接了以下库:

-lg -lstdc++ -lgcc -lm -lrdimon -lc

如果有人能帮我找到这个问题的真正根源,我将不胜感激。 不过,既然解决了我的问题,那我就关闭这个issue了。