STM32 Eclipse + ARM GNU 工具链错误链接器

STM32 Eclipse + ARM GNU toolchain error linker

我使用 Eclipse + ARM 插件来构建我的项目。当我需要在我的项目中使用 StemWin 库时,我将 IDE 配置为使用外部库。

我设置
首选项 -> C/C++ 常规 -> 路径和符号

我在 "Library Paths" 添加了 link 到我的文件夹包含库。 我还在选项卡 "Library" 中添加了我的图书馆的名称。 我检查了编译器选项卡中的设置,我确定一切都应该是好的。 当我尝试构建我的项目时,我从 linker:

收到错误消息
cannot find -lMyLib.a   Hello           C/C++ Problem

我仔细检查了我的图书馆名称和 link,都是正确的。这是我的 linker 的输出:

arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -L"C:\lib" 
-T"C:\arm_toolchain\stm32_workspace\Hello\LinkerScript.ld" -Wl,
-Map=output.map -Wl,--gc-sections -o "Hello.elf" @"objects.list" -lMyLib.a

我应该从这里做什么?

看起来问题出在 -lMyLib.a 这意味着您正在尝试 link 一个 静态库 作为一个动态库。

要link一个静态库,你必须像普通.o文件一样使用它的路径:... /path/to/MyLib.a

生成的命令行应该类似于

arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -L"C:\lib" -T"C:\arm_toolchain\stm32_workspace\Hello\LinkerScript.ld" -Wl,-Map=output.map -Wl,--gc-sections -o "Hello.elf" @"objects.list" /path/to/MyLib.a

更新:

尽管它可能会解决问题,但事实并非如此:

-llibrary

-l library

... Normally the files found this way are library files—archive files whose members are object files. The linker handles an archive file by scanning through it for members which define symbols that have so far been referenced but not defined. But if the file that is found is an ordinary object file, it is linked in the usual fashion. The only difference between using an -l option and specifying a file name is that -l surrounds library with ‘lib’ and ‘.a’ and searches several directories.

(https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html)

链接器的 -l 选项(假设您将 -lMyLib.a 作为链接器选项)的约定是搜索在给定名称并附加 .a(或 .so),即您的命令行搜索文件 libMyLib.a.{a,so},这可能不是它的命名方式。

您可以根据此约定重命名您的库,或者将其提供给链接器命令行,省略 -l(前提是您的 IDE 允许您这样做)。

我以前遇到过同样的问题。

-l:STemWin526_CM4_GCC.a  
-L"C:\Edu_Workspace\STM32F4\stm32f4_bsp_template\Drivers\Middlewares\ST\STemWin\Lib"  

以上是我的工作设置。

对于 -l:<archive file name>,冒号 : 对于存档文件链接很重要。

-L将包含库路径。 同样对于 stemwin,请确保使用硬件浮点进行编译

-mfloat-abi=hard -mfpu=fpv4-sp-d16