2012-09-04 2 views
1
나는 다음과 같은 오류가 발생

:LNK2019 오류

1>main.obj : error LNK2019: unresolved external symbol "void __cdecl setup(void)" ([email protected]@YAXXZ) referenced in function _main 1>main.obj : error LNK2019: unresolved external symbol "void __cdecl display(void)" ([email protected]@YAXXZ) referenced in function _main 1>C:\code\Project1\Debug\Project1.exe : fatal error LNK1120: 2 unresolved externals

내가이 문제를 어떻게 해결합니까? 여기

이 기능을 사용하는 메인 클래스입니다 :

여기
#include "interface.h" 
using namespace std; 

int main(){ 
    setup(); 
    display(); 
    system("pause"); 
    return 0; 
} 

이 interface.cpp

#include <iostream> 
#include <string> 
#include "interface.h" 
using namespace std; 
class ui{ 
    void setup(){ 
     options[0][0]="Hello"; 
     options[1][0]="Hello"; 
     options[2][0]="Hello"; 
     options[3][0]="Hello"; 
     options[4][0]="Hello"; 
     options[5][0]="Hello"; 
     options[6][0]="Hello"; 
     options[7][0]="Hello"; 
     options[8][0]="Hello"; 
     options[9][0]="Hello"; 
    } 
    void changeOption(int whatOption, string whatText, 
        string prop1, string prop2, string prop3, string prop4, string prop5){ 
     options[whatOption][0]=whatText; 
     options[whatOption][1]=prop1; 
     options[whatOption][2]=prop2; 
     options[whatOption][3]=prop3; 
     options[whatOption][4]=prop4; 
     options[whatOption][5]=prop5; 
    } 
    void display(){ 
     for(int x=0;x<9;x++){ 
      cout<<options[x][0]<<endl; 
     } 
    } 
}; 

이며, 여기

#include <string> 
//#include <iostream> 
using namespace std; 
#ifndef INTERFACE_H_INCLUDED 
#define INTERFACE_H_INCLUDED 
    void setup(); 
    extern string options[10][6]; 
    void changeOption(int whatOption, string whatText, string prop1, string prop2, string prop3, string prop4, string prop5); 
    void display(); 
#endif INTERFACE_H 
+0

그것은 현재 상황에서 많은 도움이되지는 않지만 장기간 프로그래밍에서는 : inteface.h'에서 포함 가드 바깥에 아무것도 넣지 마십시오. – ch0kee

+0

꽤 좋은 질문입니다! –

답변

3

전역 함수로 선언합니다.

그러나 구현시 내부에 class ui{을 정의합니다.

class ui{ 및 일치하는 닫는 괄호를 제거하면 제대로 작동합니다.

+0

이제 이것을 말합니다 : interface.obj : 오류 LNK2001 : 해결되지 않은 외부 기호 "class std :: basic_string , class std :: allocator > (* options) [?] 옵션 @@ 3PAY05V? $ basic_string @ DU? $ char_traits @ D @ std @@ V? $ allocator @D @ 2 @@ std @@ A) –

+1

문자열 옵션을 정의합니다 [10] [6]; 어딘가에서'interface.cpp'에'string options [10] [6];'. 당신은'interface.h'에'extern'을 선언했습니다. 당신이 다른 곳에서 정의 할 것이라고 약속했습니다. – ch0kee

+0

감사합니다. –

0

귀하의 setup() interface.h 함수는 ui 네임 스페이스 안에 있지만 사용하려고하면 그쪽을 지정하지 않습니다. 티. 대신 ui::setup();을 시도하십시오.

display()에 대한 동일한 솔루션.

이 외에도 interface.h 헤더 파일을 다시 검토해야합니다. 여기서는 네임 스페이스에 선언을 포함하지 않고 이러한 함수를 선언합니다. 이것이 main() 함수를 컴파일 할 수 있었지만 그것을 링크 할 수없는 이유입니다.

+0

"ui"클래스에서 구현되었으므로 실제로는 충분하지 않을 것입니다. 그러나 헤더에서 그런 식으로 구현되지는 않습니다 ... –

+0

좋은 지적입니다., 감사합니다. 내 대답을 업데이트 할게. – mah