c - Multiple definition of a symbol while building a shared library with static libraries -
c - Multiple definition of a symbol while building a shared library with static libraries -
i have build single shared library multiple object files. lets object file obj1.o , obj2.o kept under obj_folder , both utilize mutual function foo(). function foo() defined in cpp file lets phone call foo.cpp. ibject of foo.cpp nowadays under obj_folder.
scenario below:
in obj1.cpp void func1() { int timestamp =foo(); } in obj2.cpp void func2() { int timestamp = foo(); } both files have obj1.o , obj2.o build separately. thinking here both obj1.o , obj2.o have statically build code foo() , while in building linker cant find object should pick foo() location.
building shared object project.so utilize next command -
gcc -shared -fpic obj_folder/*.o -o project.so building shared object see error message -
multiple definition of foo() how can resolve symbol collision , build shared librray?
multiple definition of foo() how can resolve symbol collision , build shared librray?
unfortunately have not provided plenty info reply question.
your description appears imply foo defined in foo.o, if so, wouldn't link error getting.
the first step hence find out foo actually defined. here recipe so:
nm -a obj_folder/*.o | grep ' foo$' for link error create sense, there should 2 separate .o files foo defined in each one. when linking library, you'll have rid of 1 of them.
p.s. don't phone call directories "folder".
p.p.s. linking library so: gcc ... obj_folder/*.o -o project.so bad idea(tm). larn , utilize make.
c linux unix gcc shared-libraries
Comments
Post a Comment