【发布时间】:2016-06-13 12:11:27
【问题描述】:
在尝试编译使用 Throw The Switch 的 Unity 测试框架编写的测试时,我在链接器的某个地方遇到了一些问题。我还有其他测试可以编译和运行得非常好,所以我肯定只是在启用双浮点比较的断言助手时遗漏了一些东西。
头文件中有文档告诉我们如何启用双浮点比较。
* - define UNITY_INCLUDE_DOUBLE to allow double floating point comparisons
但是,我最终得到了这个错误:
Undefined symbols for architecture x86_64:
"_UnityAssertDoublesWithin", referenced from:
_test_example in main-6fae82.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我写了一个最简单的例子来复制这个:
#define UNITY_INCLUDE_DOUBLE
#include "unity.h"
void test_example(void)
{
TEST_ASSERT_EQUAL_DOUBLE(1.234, 1.234);
}
int main(void) {
UNITY_BEGIN();
RUN_TEST(test_example);
return UNITY_END();
}
示例的 CWD 内容和调用 clang 的确切命令(再次显示相同的错误):
$ ls
main.c unity.c unity.h unity_internals.h
$ clang unity.c main.c
Undefined symbols for architecture x86_64:
"_UnityAssertDoublesWithin", referenced from:
_test_example in main-ee77c2.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
gcc 也发生了同样的事情(但实际上它只是在后台调用 clang)。
我很确定我只是错过了一小步,但对于我的一生来说,我现在看不到它是什么。提前感谢您的帮助。
【问题讨论】:
-
作为数据点,我通过在 unity_config.h 文件中使用相同的定义并添加
UNITY_INCLUDE_CONFIG_H作为编译器-D标志 (gcc) 来处理我的最小测试。但是使用#define 运行并不能达到同样的效果。
标签: c gcc compiler-errors linker clang