XCTest 测试 C 函数构建失败

XCTest test C function build Failed

我写了一个 C 函数,当我想在 Xcode 中使用 XCTest 测试这个函数时,出现错误。


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

当我按下 command + 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)

帮助,谢谢。

我找到原因了。

我需要将实现文件(*.c 文件)添加到单元测试目标以便编译。包含 header 是不够的。