I declared an external function with a weak GCC attribute in the .c file:
extern int weakFunction( ) __attribute__ ((weak));
The compiled object file has a weak function, defined as a weak symbol. Output signal nm:
1791: w weakFunction
I call a weak defined function as follows:
if (weakFunction != NULL) { weakFunction(); }
When I link the program, defining object files as parameters for GCC ( gcc main.o weakf.o -o main.exe ), weak characters work fine. If I leave a weak .o signal from the link, the function address will be NULL in main.c and the function will not be called.
The problem is that when weakf.o is inside the static library, for some reason the linker cannot find this function, and the address of the function always ends as NULL. A static library is created using ar: ar rcs weaklibrary weakf.o
Has anyone had similar problems?
source share