Hello everybody. First, I would like to introduce my problem to you all!
I am using Atollic TrueStudio to develop an Embedded System. In this system, I have a driver layer (built as a static library. This library contains basically the STM32 HAL, and this library contains A LOT of weak functions). These library is being compiled with ARM GCC and works great. I can link it in other projects and it does work as it should.
The second part is the problem, because I want to implement Unit Testing in the project!
For this, I have created another configuration for the same Driver Layer static library (the one with STM32 HAL code), but this time I'm compiling it with MinGW. The compilation works, but when I Try to link this library into another project (an executable project). The Linker returns "undefined reference to ..." (Image below).
PS: The problem is with the Linker, since the project finds where the weak function is declared. It can not find where it's defined though!
Edit
This is the main code
#include <MbedOS/platform/mbed_error.h>
int main(void)
{
error("Stream obj failure, errno=%d\r\n",
return 0;
}
This is where the function is defined (inside the static library) mbed_error.c
#include <MbedOS/platform/mbed_error.h>
static uint8_t error_in_progress = 0;
WEAK void error(const char* format,
...)
{
// Prevent recursion if error is called again
if (error_in_progress)
{
return;
}
error_in_progress = 1;
#ifndef NDEBUG
va_list arg;
va_start(arg,
format);
mbed_error_vfprintf(format,
arg);
va_end(arg);
#endif
exit(1);
}
This is mbed_error.h file
#ifdef __cplusplus
extern "C"
{
#endif
void error(const char* format,
...);
#ifdef __cplusplus
}
#endif
And this is the result from the console
13:45:44 **** Build of configuration Debug for project testeLINKER ****
make all
gcc -o "testeLINKER.elf" ./src/main.o -lSTM32F7_Driver_Layer -L"E:\TrueStudio_Projects\STM32F7_Driver_Layer\Projeto\TrueStudio\UnitTestLibrary"
./src/main.o: In function `main':
E:\TrueStudio_Projects\testeLINKER\Debug/../src/main.c:33: undefined reference to `error'
collect2.exe: error: ld returned 1 exit status
make: *** [testeLINKER.elf] Error 1
13:45:44 Build Finished (took 460ms)
Edit 2 The nm output for the static library follows (just one of the files with a weak function)
C:\Program Files (x86)\Atollic\TrueSTUDIO for STM32 9.0.0\PCTools\bin>nm E:\TrueStudio_Projects\STM32F7_Driver_Layer\Projeto\TrueStudio\UnitTestLibrary\Source\MbedOS\platform\mbed_error.o
00000000 b .bss
00000000 d .data
00000000 N .debug_abbrev
00000000 N .debug_aranges
00000000 N .debug_info
00000000 N .debug_line
00000000 r .eh_frame
00000000 r .rdata$zzz
00000000 t .text
00000000 T .weak._error.
w _error
00000000 b _error_in_progress
U _exit
U _mbed_error_vfprintf
{ }button to format it as code. - divibisan