I have to build a single shared library from multiple object files. Lets say object file Obj1.o and Obj2.o kept under obj_folder and both use a common function foo(). function foo() is defined in another cpp file lets call it foo.cpp. The ibject of foo.cpp is also present under obj_folder.
Scenario is as below:
In obj1.cpp
void func1()
{
int timestamp =foo();
}
in obj2.cpp
void func2()
{
int timestamp = foo();
}
Both files have their obj1.o and obj2.o build separately. What my thinking here is both obj1.o and obj2.o have statically build code for foo() and while in building linker just cant find from which object it should pick foo() location.
building shared object project.so i use following command -
gcc -shared -fPIC obj_folder/*.o -o project.so
building shared object i see error message -
Multiple definition of foo()
How i can resolve this symbol collision and build my shared librray?
externkeyword (and include it when needed). - Michael Petchfoois defined. - R.. GitHub STOP HELPING ICE