2010-04-14 7 views
0

정의되지 않은 참조를 이해할 수 없습니다.cxxtest를 실행할 때 정의되지 않은 참조 오류가 발생합니다.

./cxxtest/cxxtestgen.py -o tests.cpp --error-printer DrawTestSuite.h 
g++ -I./cxxtest/ -c tests.cpp 
g++ -o tests tests.o Color.o 
tests.o: In function `DrawTestSuite::testLinewidthOne()': 
tests.cpp:(.text._ZN13DrawTestSuite16t… undefined reference to `Linewidth::Linewidth(double)' 
tests.cpp:(.text._ZN13DrawTestSuite16t… undefined reference to `Linewidth::draw(std::basic_ostream<char… std::char_traits<char> >&)' 
collect2: ld returned 1 exit status 
make: *** [tests] Error 1// DrawTestSuite.h 

DrawTestSuite.h은 단위 테스트를 포함하고, 시험 함수는 constructer 부재 함수 추첨을 실행하도록 촉구 Linewidth.h.

나는 DrawTestSuite.h에 #include "Linewidth.h"을 가지고 있습니다.

답변

1

"정의되지 않은 참조"는 함수를 올바르게 선언하고 사용했지만 연결시 정의가 포함되지 않은 경우 링커 오류입니다.

Linewdith.cpp를 컴파일 할 때 사용한 개체 파일 인 Linewidth.o와 해당 함수가 구현 될 가능성이있는 위치와 연결해야합니다.

종속성을 지정하는 방법을 알기 위해 cxxtest에 익숙하지 않지만 간단한 선언 만 필요합니다.

+1

+1. 세번째 줄은'g ++ -o tests tests.o Color.o Linewidth.o' –

+0

@Draco : 실행중인 명령어를 보여주는 make이며 makefile을 생성 할 수 있습니다. (그렇지 않은 경우 단순히 적절한 "tests : Linewidth.o"규칙을 포함 시켜서 "Linewidth.o"를 종속성으로 추가합니다.) –

+0

나는 그것이 makefile이라는 것을 알고 있습니다. :) –

관련 문제