ST意法半导体
直播中

李华

7年用户 1285经验值
私信 关注
[问答]

有没有哪位大神指导使用静态库的链接器错误该怎么解决啊

我使用开源项目(github 上的 open62541)通过 lwip 获取 OPC-UA 实现。
当我的项目使用 open62541 源代码编译时,它可以正常工作。
但是生成的 2 个文件“open62541.c”和“open62541.h”非常大(大约 4 和 1 MB)。
我的交叉编译器是 STM32CubeIDE 版本 1.9 的 gcc
   STM32 的 GNU 工具 (10.3-2021.10)
   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-2021.10.win32_1.0.0.202111181127/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-2021.10.20211105-1100.....
  • Thread model: single
  • Supported LTO compression algorithms: zlib
  • gcc version 10.3.1 20210824 (release) (GNU Tools for STM32 10.3-2021.10.20211105-1100)
为了优化我的编译操作,我想为 open62541 函数创建一个库。
我编译 open62541 源代码以获得 libopen62541.a 文件,然后将此库与我的项目链接。
我有一些链接器错误,如下所示:
  • arm-none-eabi-gcc -o "STM32_TBUS.elf" @"objects.list" -lmbedtls -lopen62541-mbedtls -mcpu=cortex-m7 -T"D:STSTM32CubeIDEworkspaceSTM32_TBUSSTM32H743ZITx_FLASH.ld" --specs=nosys.specs -Wl,-Map="STM32_TBUS.map" -Wl,--gc-sections -static -L"D:STSTM32CubeIDEworkspaceSTM32_TBUSLibmbedtls" -L"D:STSTM32CubeIDEworkspaceSTM32_TBUSLibOPC-UA" --specs=nano.specs -mfpu=fpv5-d16 -mfloat-abi=hard -mthumb -Wl,--start-group -lc -lm -Wl,--end-group
  •    c:ststm32cubeide_1.9.0stm32cubeidepluginscom.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-2021.10.win32_1.0.0.202111181127toolsarm-none-eabibinld.exe: D:STSTM32CubeIDEworkspaceSTM32_TBUSLibOPC-UAlibopen62541-mbedtls.a(open62541.o): in function `ServerNetworkLayerTCP_close':
  •    open62541.c:(.text.ServerNetworkLayerTCP_close+0xc): undefined reference to `lwip_shutdown'
  •    c:ststm32cubeide_1.9.0stm32cubeidepluginscom.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-2021.10.win32_1.0.0.202111181127toolsarm-none-eabibinld.exe: D:STSTM32CubeIDEworkspaceSTM32_TBUSLibOPC-UAlibopen62541-mbedtls.a(open62541.o): in function `connection_write':
  •    open62541.c:(.text.connection_write+0x30): undefined reference to `lwip_send'
  •    c:ststm32cubeide_1.9.0stm32cubeidepluginscom.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-2021.10.win32_1.0.0.202111181127toolsarm-none-eabibinld.exe: open62541.c:(.text.connection_write+0x52): undefined reference to `lwip_poll'
  •    c:ststm32cubeide_1.9.0stm32cubeidepluginscom.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-2021.10.win32_1.0.0.202111181127toolsarm-none-eabibinld.exe: D:STSTM32CubeIDEworkspaceSTM32_TBUSLibOPC-UAlibopen62541-mbedtls.a(open62541.o): in function `connection_recv':
  •    open62541.c:(.text.connection_recv+0x50): undefined reference to `lwip_select'
  •    ...

我怀疑从库中调用的函数没有正确链接,也许优化器从主代码中删除了一些不使用的函数。
但是这些函数是从库中使用的。
  • --[ main_code ] --> [open62541 library] ---|
  • --[ lwip stack ] < ------------------------|
找不到的功能是lwip的功能。
如果有人有任何想法,感谢您的帮助。

回帖(1)

孙宇

2022-12-2 15:42:12
谢谢“Pavel A.”,但我发现了我的问题。
当我制作 libopen62541.a 库时,我忘记定义值为 2 的 LWIP_COMPAT_SOCKETS。
所以 lwip 函数是未定义的,当我将库链接到我的主项目时,链接器失败了。
举报

更多回帖

发帖
×
20
完善资料,
赚取积分