【问题标题】:undefined reference to `UNITY_BEGIN' and 'UNITY_END'未定义对“UNITY_BEGIN”和“UNITY_END”的引用
【发布时间】: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_BEGINUNITY_END 时,我可以编译它,并且冒烟测试运行没有问题。

【问题讨论】:

    标签: c unit-testing gcc makefile linker


    【解决方案1】:

    我可以通过不使用发布版本 2.1.0 来解决它。 为了解决这个问题,我克隆了当前的 master 分支,它甚至可以使用 UNITY_BEGINUNITY_END

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

    【讨论】:

      猜你喜欢
      • 2012-05-12
      • 2018-06-17
      • 2016-02-23
      • 2012-01-30
      • 2011-08-01
      • 2015-02-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多