googlemock - 如何处理"多重定义"问题?
googlemock - how do I deal with "multiple definition" problems?
在我的CMakeLists.txt文件中,我有:
include_directories("${algorithm}/include")
add_executable(
test_runner
test_runner.cpp
test_file1.cpp
test_file2.cpp
test_file2.cpp
)
target_link_libraries(
test_runner
gtest_main)
gtest_discover_tests(test_runner)
不幸的是,这不起作用,因为这些文件都从"${algorithm}/include"
导入algorithm.c
。
我不知道在这里做什么。我怎样才能有多个test_files,这些都依赖于algorithm.c
,test_runner
可以发现?
我是被迫将所有test_files放入一个文件中,还是为每个文件制作单独的可执行文件?那将是极其不幸的。
有没有其他选择?我期待涉及标题的东西?还是algorithms.c
需要是我导入的库?
您可以将源文件的包含包装到具有适当包含保护的其他头文件中。像这样:
// File: algorithm_test.h
#ifndef ALGORITHM_TEST_H
#define ALGORITHM_TEST_H
#include <algorithm.c>
#endif /* ALGORITHM_TEST_H */
之后,您的测试(test_file1.cpp
、test_file2.cpp
等(可能包含此标头,而不是直接包含源文件:
// File: test_file1.cpp
#include <algorithm_test.h>
... define test methods ...
相关文章:
- Visual Studio中的函数声明和函数定义问题
- 使用自定义比较函数使用std::sort()对矢量字符串进行排序时出现问题
- Cmake 链接问题:未定义对 Button::mousePressEvent(QGraphicsSceneMouseE
- 如何在标头中声明(或定义)函数的问题
- Xcode 语义问题引用或以前定义的代码
- 我的超类中的模板问题与结构定义
- Arduino:在 loop() 和自定义函数中运行相同的代码时出现问题
- 编译问题:在函数"_start"中:未定义对"主"的引用 collect2:错误:ld 返回 1 个退出状态
- googlemock - 如何处理"多重定义"问题?
- 使用前向声明的类重定义问题
- 模板多个定义问题
- std::ofstream 变量定义问题
- 重新定义C++问题,多个标头
- 重新排序包含目录如何解决宏重定义问题
- 类型定义问题
- 预处理器:生成具有动态名称的函数.多个定义问题
- C++通用定义问题(ADT、成员、构造函数和重载)
- c++头文件和类定义问题
- 编译器错误-定义问题.C++
- C&C++默认全局变量链接,多重声明和定义问题