cancel
Showing results for 
Search instead for 
Did you mean: 

Linker error using static library

thln47
Associate III

Hello,

I use an open source projet (open62541 on github) to get OPC-UA implementation over lwip.

When my projet is compiled with open62541 source code, it's works without error.

But the 2 files generated 'open62541.c' and 'open62541.h' are very big (around 4 and 1 Mbytes).

My cross compiler is gcc form STM32CubeIDE Version 1.9

   GNU Tools for STM32 (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)

To optimize my compilation operation, I want to make a library for open62541 functions.

I compile open62541 source code to get a libopen62541.a file, then I link this library with my projet.

I've some linker error, as you can see below:

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.202111181127\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.202111181127\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.202111181127\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.202111181127\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'
 
   ...
 
 

I suspect that functions called from library are not correctly linked, perhaps the optimizer remove some function not use from the main code.

But theses functions are used from the library.

--[ main_code ] --> [open62541 library] ---|
--[ lwip stack ] < ------------------------|

The functions not found are those of lwip.

If anyone has any idea, thanks for your help.

1 ACCEPTED SOLUTION

Accepted Solutions
thln47
Associate III

Thanks "Pavel A.", but I found my problem.

When I made the libopen62541.a library, I've forget to define LWIP_COMPAT_SOCKETS with value 2.

So lwip functions was undefined, and when I link the library with my main project, the linker failed.

View solution in original post

2 REPLIES 2
thln47
Associate III

Thanks "Pavel A.", but I found my problem.

When I made the libopen62541.a library, I've forget to define LWIP_COMPAT_SOCKETS with value 2.

So lwip functions was undefined, and when I link the library with my main project, the linker failed.