2017-10-17 10 views
0

세 개의 파일이있는 간단한 프로젝트가 있습니다. Main.cpp, CountTriangles.cpp 및 CountTriangles.hpp. 빌드/실행하려고하면 "링커 명령이 종료 코드 1과 함께 실패했습니다."라는 메시지가 표시되고 로그에서 "x86_64 아키텍처의 ld : 1 중복 심볼"을 찾습니다.링커 명령이 실패했습니다. 중복 된 심볼

는 MAIN.CPP :

#include "CountTriangles.cpp" 

int main(int argc, const char * argv[]) { 
    return 0; 
} 

CountTriangles.cpp :

#include "CountTriangles.hpp" 
using namespace std; 

int TriangleCount::count(int N){ 
    int helper = 1; 
    return helper; 
} 

CountTriangles.hpp : main.cpp에서

#ifndef CountTriangles_hpp 
#define CountTriangles_hpp 

#include <iostream> 
#include <stdio.h> 

class TriangleCount{ 
    public: 
     int count(int N); 
}; 

#endif /* CountTriangles_hpp */ 
+1

헤더 파일이 아닌 * 소스 파일을 포함합니다. 그러지 마. –

+0

주에서는 .hpp 파일 대신'#include "CountTriangles.cpp"를 포함합니다. –

+2

앞으로의 질문은 좋은 질문을하는 방법을 읽어보십시오.] (http://stackoverflow.com/help/how-to-ask). 오류 출력을 실제로 복사 * 붙여 넣기 *해야합니다. 존재할 수있는 정보 메모가 완전하고 완성됩니다. –

답변

1

당신은 #include "CountTriangles.cpp" 포함하지만 당신은 헤더를 포함에 있어야합니다 CountTriangles.hpp

TriangleCount::count(int N)의 정의가 두 번 컴파일되고 다시 정의되면 결과 중복 심볼 오류가 발생합니다.