duplicate symbol '_s_Variable' in: /var/folders/wb/pjgtxmjd1pd76j9qs__63hh40000gp/T/main-71027a.o /var/folders/wb/pjgtxmjd1pd76j9qs__63hh40000gp/T/static-7f2470.o ld: 1 duplicate symbol for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
voidPrint(){ std::cout << x << " " << y << std::endl; } };
intmain(){ Entity e; e.x = 1; e.y = 2;
Entity e1; e1.x = 5; e1.y = 8;
e.Print(); e1.Print(); return0; }
编译:
1
g++ -o test.o static_class.cpp
输出:
1 2 3 4 5 6 7 8 9
Undefined symbols for architecture x86_64: "Entity::x", referenced from: _main in static_class-65b492.o Entity::Print() in static_class-65b492.o "Entity::y", referenced from: _main in static_class-65b492.o Entity::Print() in static_class-65b492.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)