5

I have created two static libraries for use with a C program I am writing for an ARM STM32F4xx processor using Mentor Graphics CodeSourcery. I have added the libraries and their directories to the build settings in the project as I believe they are supposed to be (Under properties, C/C++ Build->Settings->Tool Settings->Sourcery CodeBench C Linker->Libraries) but when I compile and link the project, I get undefined reference errors to functions in one of the libraries. I have tried changing the order of the libraries relative to each other. I have include a snippet below of the compiler log edited to clean up the long path names.

I am at a complete loss here so any help is appreciated.

'Building target: Firmware_Development'
'Invoking: Sourcery CodeBench C Linker'
arm-none-eabi-gcc -L"Libary1-Folder-Path" -L"Library2-Folder-Path" -Xlinker -Map="Firmware_Development.map" -T "firmware-rom-hosted.ld -mcpu=cortex-m4 -mthumb -o "Firmware_Development" "@objs.rsp" "@user_objs.rsp" "@libs.rsp"
src/main.o: In function `program_loop':
\\Debug/../src/main.c:99: undefined reference to `LwIP_Pkt_Handle'
\\Debug/../src/main.c:103: undefined reference to `LwIP_Periodic_Handle'
src/stm32f4xx_it.o: In function `__cs3_isr_exti15_10':
\\Debug/../src/stm32f4xx_it.c:187: undefined reference to `Eth_Link_ITHandler'
src/Config.o: In function `Communication_Init':
\\Debug/../Libraries_Firmware/src/Config.c:175: undefined reference to `ETH_BSP_Config'
\\Debug/../Libraries_Firmware/src/Config.c:178: undefined reference to `LwIP_Init'
collect2.exe: error: ld returned 1 exit status
cs-make: *** [Firmware_Development] Error 1
Jared
  • 1,449
  • 2
  • 19
  • 40
  • 1
    First thing to do would be to use objdump to verify that these functions are provided by the libraries... Next, make sure that your build script variables are actually expanding either to some -l flags or explicit mention of the actual library files. If you want to get trickier, you can rename the libraries and make sure that the build fails due to being unable to find them - if it doesn't, it means you haven't managed to tell the linker to use them. – Chris Stratton Dec 04 '13 at 23:02
  • @ChrisStratton - Thanks. I have confirmed that the build system has added the libraries in the file 'libs.rsp' so they are also the last part of the command. I'm checking on the symbols now. – Jared Dec 04 '13 at 23:15
  • @ChrisStratton I owe you one. Create the answer and I'll accept it if you want the credit. – Jared Dec 04 '13 at 23:33
  • Your welcome, but since I don't yet know what the actual problem you found was, perhaps you should just write your own answer with what you found and then you can (eventually) accept that to resolve the question. – Chris Stratton Dec 04 '13 at 23:37
  • True. It turned out when I factored out some common code from projects into a library I omitted a source file which became apparent when examining the symbols with objdump as you suggested. Adding the relevant source and rebuilding the library took care of the problem. – Jared Dec 04 '13 at 23:40
  • 1
    You should post this as an answer and mark the question as answered. There is no problem with answering your own question, you can even tag your answer as "community wiki" if you don't want to take points for it. – Étienne Dec 12 '13 at 19:11
  • @Étienne you are correct. Completed. – Jared Dec 12 '13 at 22:29

1 Answers1

1

For those coming here via searches, the problem was exactly as @ChrisStratton suggested. The code was originally created as a single project and I opted to factor out a large portion of it into a library. When I did this I factored out a header file but missed its corresponding source file so everything compiled fine but failed on link. Checking the objdump made this pretty evident as the objects did not exist.

Jared
  • 1,449
  • 2
  • 19
  • 40