gpt4 book ai didi

c - 对 `UNITY_BEGIN' 和 'UNITY_END' 的 undefined reference

转载 作者:行者123 更新时间:2023-11-30 16:58:16 26 4
gpt4 key购买 nike

我想使用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_BEGINUNITY_END 时,我可以编译它并且烟雾测试运行没有问题。

最佳答案

我可以通过不使用发行版 2.1.0 来解决这个问题。为了解决这个问题,我克隆了当前的主分支,它甚至可以与 UNITY_BEGINUNITY_END 一起使用:

git clone https://github.com/ThrowTheSwitch/Unity.git

关于c - 对 `UNITY_BEGIN' 和 'UNITY_END' 的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38995065/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com