2010-04-14 114 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包含單元測試和測試函數調用Linewidth.h來執行構造函數和成員函數的繪製。

我在DrawTestSuite.h中有#include "Linewidth.h"

回答

1

當未正確聲明和使用函數時,「未定義的引用」是鏈接器錯誤,但鏈接時定義未包含。

您需要鏈接Linewidth.o,它是編譯Linewdith.cpp時的對象文件以及實現這些函數的可能位置。

我不熟悉cxxtest知道它期望你如何指定依賴關係,但我懷疑它只需要一個簡單的聲明。

+1

+1。第三行應該是'g ++ -o tests tests.o Color.o Linewidth.o' – 2010-04-14 06:58:45

+0

@Draco:這就是顯示正在執行的命令,並且可以生成makefile。 (如果不是,只需包含適當的「tests:Linewidth.o」規則,即添加「Linewidth.o」作爲依賴項。) – 2010-04-14 07:01:35

+0

我知道它是makefile :) – 2010-04-14 07:12:46

相關問題