【发布时间】:2016-08-17 11:14:06
【问题描述】:
我想使用Unity 对我的 C 代码进行单元测试,但编译时出现以下错误:
$ make
gcc ../Unity/src/unity.o src/helpers.o src/chess.o src/search.o test/TestCheck.o src/main.o -o checkai
src/main.o: In function `main':
main.c:(.text+0x4b): undefined reference to `UNITY_BEGIN'
main.c:(.text+0x55): undefined reference to `UNITY_END'
collect2: error: ld returned 1 exit status
make: *** [Makefile:11: checkai] Error 1
$ make -n
gcc ../Unity/src/unity.o src/helpers.o src/chess.o src/search.o test/TestCheck.o src/main.o -o checkai
我的主要功能看起来像这样:
#include <stdio.h>
#include <stdlib.h>
#include "helpers.h"
#include "chess.h"
#include "../../Unity/src/unity.h"
//#include "../test/TestCheck.h"
void test_Smoke(void) {
TEST_ASSERT_EQUAL_INT(1, 2);
}
int main() {
version();
chesspiece chessboard[8][8];
initField(chessboard);
UNITY_BEGIN();
RUN_TEST(test_Smoke, 1);
return UNITY_END();
}
我是否链接错误?我已经尝试更改 gcc 命令的顺序,但没有任何帮助。
当我注释掉 UNITY_BEGIN 和 UNITY_END 时,我可以编译它,并且冒烟测试运行没有问题。
【问题讨论】:
标签: c unit-testing gcc makefile linker