I am trying to link two libraries libA.a and libB.a along with a main.c file. libB has dependencies on libA, and main has dependencies on both.
I am able to compile the libraries independently, but when I try to link them together to create the final executable, I get the error that references to functions of A by B are not defined.
Is there any way to tell the linker to search for these functions in libA?
- I am going to run this code on FreeRTOS on Cortex-M3 MCU so static linking is my only option.
- I really want to be able to do this without changing the compile process for libB.
There is a similar question at this link but as I said, dynamic linking is not an option.
As requested by Ofek a toy code (ignore functionality and syntax errors, if any)-
libA
int libA_fun1()
{ return stuff; }
int libA_fun2()
{ return something_else; }
libB
#include <libA.h>
int libB_fun1()
{
//do stuff
int x = libA_fun1();
return something;
}
main.c
#include <libA.h>
#include <libB.h>
int main()
{
printf("%d", libA_fun2() * libB_fun1());
return 0;
}
I build libA.a and libB.a. Finally
gcc main.c -lA -lB -LPathA -LPathB
gives the error: undefined reference to libA_fun1 in libB_filexx.c, line xx
However, the function is properly defined in libA.h