[STM32H7] 链接错误使用静态库。

[复制链接]
60|0
唐纳德d 发表于 2025-10-12 21:19 | 显示全部楼层 |阅读模式
我使用一个开源项目(GitHub上的open62541)来在lwip上实现OPC-UA。

当我的项目与open62541源代码一起编译时,没有错误,运行正常。

但生成的两个文件“open62541.c”和“open62541.h”非常大(分别约为4MB和1MB)。

我的交叉编译器是STM32CubeIDE中的GCC:GNU Tools for STM32  arm-none-eabi-gcc -v
Using built-in specs.
OLLECT_GCC=arm-none-eabi-gcc
COLLECT_LTO_WRAPPER=c:/st/stm32cubeide_1.9.0/stm32cubeide/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-.win32_1.0.0./tools/bin/../lib/gcc/arm-none-eabi/10.3.1/lto-wrapper.exe
Target: arm-none-eabi
Configured with: /build/gnu-tools-for-stm32_10.3.....
Thread model: single
Supported LTO compression algorithms: zlib
gcc version 10.3.1 (release) (GNU Tools for STM32 10.3-1100)

为了优化编译操作,我想为open62541函数创建一个库。

将open62541源代码编译成libopen62541.a文件,然后将该库与我的项目链接。

出现了一些链接错误,如下所示:
arm-none-eabi-gcc -o "STM32_TBUS.elf" @"objects.list" -lmbedtls -lopen62541-mbedtls -mcpu=cortex-m7 -T"D:\ST\STM32CubeIDE\workspace\STM32_TBUS\STM32H743ZITx_FLASH.ld" --specs=nosys.specs -Wl,-Map="STM32_TBUS.map" -Wl,--gc-sections -static -L"D:\ST\STM32CubeIDE\workspace\STM32_TBUS\Lib\mbedtls" -L"D:\ST\STM32CubeIDE\workspace\STM32_TBUS\Lib\OPC-UA" --specs=nano.specs -mfpu=fpv5-d16 -mfloat-abi=hard -mthumb -Wl,--start-group -lc -lm -Wl,--end-group

   c:\st\stm32cubeide_1.9.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-2021.10.win32_1.0.0.\tools\arm-none-eabi\bin\ld.exe: D:\ST\STM32CubeIDE\workspace\STM32_TBUS\Lib\OPC-UA\libopen62541-mbedtls.a(open62541.o): in function `ServerNetworkLayerTCP_close':

   open62541.c:(.text.ServerNetworkLayerTCP_close+0xc): undefined reference to `lwip_shutdown'

   c:\st\stm32cubeide_1.9.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-2021.10.win32_1.0.0.\tools\arm-none-eabi\bin\ld.exe: D:\ST\STM32CubeIDE\workspace\STM32_TBUS\Lib\OPC-UA\libopen62541-mbedtls.a(open62541.o): in function `connection_write':

   open62541.c:(.text.connection_write+0x30): undefined reference to `lwip_send'

   c:\st\stm32cubeide_1.9.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-2021.10.win32_1.0.0.\tools\arm-none-eabi\bin\ld.exe: open62541.c:(.text.connection_write+0x52): undefined reference to `lwip_poll'

   c:\st\stm32cubeide_1.9.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-2021.10.win32_1.0.0.tools\arm-none-eabi\bin\ld.exe: D:\ST\STM32CubeIDE\workspace\STM32_TBUS\Lib\OPC-UA\libopen62541-mbedtls.a(open62541.o): in function `connection_recv':

   open62541.c:(.text.connection_recv+0x50): undefined reference to `lwip_select'

我怀疑从库中调用的函数没有正确链接,可能是优化器从主代码中移除了一些未使用的函数。

但这些函数在库中被调用了。未找到的函数是lwip的函数。
--[ main_code ] --> [open62541 library] ---|
--[ lwip stack ] < ------------------------|

您需要登录后才可以回帖 登录 | 注册

本版积分规则

57

主题

57

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部