小编Gar*_*rag的帖子

使用 cmake 的 googletest 上的依赖关系问题:gtest/gtest.h 没有这样的文件或目录

你好,

我目前正在 CMake 上工作,以便在工作中使用 ExternalProject_add。因为我想测试 googletest,所以我尝试测试两者。我在编译单元测试代码时遇到问题。

所以我只是按照 github 上 googletest 项目的自述文件:https://github.com/google/googletest/blob/master/googletest/README.md#incorporating-into-an-existing-cmake-project

这是我的项目树:

test_cpp/
??? build
??? CMakeLists.txt
??? CMakeLists.txt.in
??? inc
?   ??? foo.h
??? src
?   ??? foo.c
??? test
    ??? test_foo.c
Run Code Online (Sandbox Code Playgroud)

我的 test_foo.c 只是在 foo 中测试一个函数,它是一个 double :

#include "gtest/gtest.h"
#include "foo.h"

TEST(AddTest, roundValue)
{
        ASSERT_EQ(roundValue(2.6),3);
}

int main(int argc, char **argv)
{
        ::testing::InitGoogleTest(&argc,argv);
        return RUN_ALL_TESTS();
}
Run Code Online (Sandbox Code Playgroud)

这是 cmake 命令的结果:

axis@axis-mad:~/Work/test_cpp/build$ cmake ..
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification …
Run Code Online (Sandbox Code Playgroud)

c++ cmake googletest

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

c++ ×1

cmake ×1

googletest ×1