더 큰 프로젝트를 만들고 있으며 클래스가 제대로 작동하는지 테스트하기 위해 3 또는 4 가지 주요 시나리오가 필요합니다. 나는이C++에서 주요 기능의 몇 가지 시나리오 만들기
#define TEST2 //INTERACTIVE OR TEST1 OR TEST2 OR TEST3
#include <iostream>
#ifdef INTERACTIVE
#include "interactive.cpp"
#endif
#ifdef TEST1
#include "test1.cpp"
#endif
#ifdef TEST2
#include "test2.cpp"
#endif
#ifdef TEST3
#include "test3.cpp"
#endif
같은 MAIN.CPP 파일을 생성하고이 테스트 파일의 모든 내부 작동해야 제 생각에는이
#include <iostream>
int main() {
//Code here
return 0;
}
같은 것입니다,하지만 난 프로젝트를 빌드 할 때 링커가 오류 :
duplicate symbol _main in:
CMakeFiles/Project.dir/main.cpp.o
CMakeFiles/Project.dir/test2.cpp.o
ld: 1 duplicate symbol for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [Project] Error 1
make[2]: *** [CMakeFiles/Project.dir/all] Error 2
make[1]: *** [CMakeFiles/Project.dir/rule] Error 2
make: *** [Project] Error 2
무엇이 잘못 되었나요?
프로젝트를 어떻게 구축하고 있습니까? IDE에서 설정 문제 일 수 있습니다. 각각의'main'은 다른 "target"과 연관되어 있어야합니다. 그래서 여러분의 코드는 오직 하나만 허용되기 때문에 많은'main's들로 만들어지지 않습니다. –