Hello,
I am trying to implement an application "hook" in a generic way in one of my custom libraries using a weak function definition but haven't been able to succeed. The overall functionality I am trying to get is similar to the one described in this Shared Example
Assuming that the library is mylib.c, mylib.h and the application in main.c, I have the following:
One of my library's functions calls ApplicationHook(), which is declared as extern in mylib.c.
If the application needs this hook then ApplicationHook() must be defined inside main.c.
However, If this hook is not needed and thus not defined in main.c, compilation will fail or even worse the program will jump to the null pointer (0), thus I want to use the weak symbol option to define a "weak" empty version of ApplicationHook() in mylib.c that will be used if and only if it is not defined anywhere else. I try to do that using in mylib.c:
void __attribute__((weak)) ApplicationHook( void );
void __attribute__((weak)) ApplicationHook( void ) { }
The compilation error goes away now when main.c does not define the hook, however when it does define it the final program still uses the empty version og mylib.c!
I am not 100% sure if I am using weak symbols correctly (I have enabled GCC extensions in CCS) or if CCS has a bug with weak symbols though.
Any help will be appreciated.
I am using CCS 5.5 with TI compiler 4.2.4.
My target is MSP430F5528 if its important.
Thanks,
Giannis