I am looking for a way to suppress/satisfy the linker when a symbol is undefined at compile time. To illustrate what I am trying to accomplish I will put up a simple example:
CoreCpp.h file:
#include <stdio.h>
int calculate();
CoreCpp.cpp file:
#include "CoreCPP.h"
int calculate(){
return 0;
}
With these two files above I will create a .a static library.
Then in Xcode I will create a simple command line project as you can see in the image below:
If I link the static library, the project will compile without any issue of course:
However, if I don't link the static library, it will throw an undefined symbol error.
Undefined symbols for architecture x86_64:
"calculate()", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
Question: Is there a way that I can suppress the error or somehow make the linker happy at compile time? Can we apply the concept of weak linking here?