Why doesn't the linker complain of duplicate symbols?
问题 I have a dummy.hpp #ifndef DUMMY #define DUMMY void dummy(); #endif and a dummy.cpp #include <iostream> void dummy() { std::cerr << "dummy" << std::endl; } and a main.cpp which use dummy() #include "dummy.hpp" int main(){ dummy(); return 0; } Then I compiled dummy.cpp to three libraries, libdummy1.a , libdummy2.a , libdummy.so : g++ -c -fPIC dummy.cpp ar rvs libdummy1.a dummy.o ar rvs libdummy2.a dummy.o g++ -shared -fPIC -o libdummy.so dummy.cpp When I try compile main and link the dummy