编译 Google 测试时出现 g++ 致命错误

g++ fatal error when compiling Google Test

我正在尝试用 Google 测试编译一些测试。我正在使用 GTEST 附带的示例 makefile,但来自不同的目录。我添加了一些 make 目标来编译我的测试和源代码,但未触及 Google 测试位,但是编译 Google 测试源失败并显示此通知:

    g++ -isystem ~/stm32/googletest/googletest/include -I~/stm32/googletest/googletest -g -Wall -Wextra -pthread -c \
            ~/stm32/googletest/googletest/src/gtest-all.cc
/home/nuclear_kiwi/stm32/googletest/googletest/src/gtest-all.cc:42:24: Fatal Error: src/gtest.cc: File or directory not found
     #include "src/gtest.cc"

为什么会失败,即使在调用编译器时提供了源路径?

您需要更改:

-I~/stm32/googletest/googletest

至:

-I ~/stm32/googletest/googletest

Bash 仅当 ~ 出现在 一个词的开头。 3.4.3. Tilde expansion