【发布时间】:2013-07-18 17:34:45
【问题描述】:
我有两个文件,first_pass.c,其中包括描述mystring.c 的mystring.h。在测试first_pass.c 时,我做了以下包括
#include "../src/mystring.c"
#include "../src/first_pass.c"
#include <gtest/gtest.h>
一切都很好,直到我不得不在mystring.h 中定义一个结构。就这么简单
typedef struct Split {
char *head;
char *tail;
}Split;
然后我在error: ‘Split’ has a previous declaration as ‘typedef struct Split Split’上编译时开始失败
课程要求使用 C(不是 C++)和 MAKE,因此不推荐使用其他测试框架,例如 Check。我知道它定义了两次结构,第一次加载mystring.c,另一次加载first_pass.c。我该怎么办?
【问题讨论】:
-
为什么要定义同一个结构两次?
-
#包含源文件(.c)自找麻烦
-
正如我在下面回答的那样,我别无选择。 googletest 文件是带有 TEST 宏的简单标头,因此要定义我的测试代码,我必须将其全部包含在内。这是我的参考:meekrosoft.wordpress.com/2009/11/09/…
标签: c include c-preprocessor googletest