2015-12-25 38 views
0

我寫了一個C函數,當我想在Xcode中使用XCTest測試這個函數時,得到一個錯誤。XCTest測試C函數構建失敗


List.h有一個函數定義。

#ifndef List_h 
#define List_h 

#include <stdio.h> 

List initList(); 

#endif /* List_h */ 

Test.m代碼 #進口 的#include 「List.h」

@interface ListTest : XCTestCase 

@end 

@implementation ListTest 

- (void)testExample { 
    initList(); 
} 

@end 

當我按下命令+ U,構建失敗!

錯誤消息:

Undefined symbols for architecture i386: 
    "_initList", referenced from: 
     -[ListTest testExample] in ListTest.o 
ld: symbol(s) not found for architecture i386 
clang: error: linker command failed with exit code 1 (use -v to see invocation) 

幫助,謝謝。

回答

0

我找到理由。

我需要將實現文件(* .c文件)添加到單元測試目標中,以便編譯進來。僅包含頭文件是不夠的。

+0

如果您必須在您的測試目標中包含實施文件,那麼您的設置不正確。我剛剛創建了一個全新的項目,並能夠從我的測試中調用我的C函數,沒問題。 –

相關問題