makefile:在 -I 之后给出的路径,但找不到头文件
makefile: path given after -I but header file not found
我正在尝试使用谷歌测试框架:https://github.com/google/googletest/tree/master/googletest。
我有 4 个文件:
阶乘.cpp:
#include "factorial.h"
int factorial(int n) { [some code here] }
法科试验.h:
int factorial(int n);
test_factorial.cpp
#include "gtest/gtest.h"
#include "factorial.h"
[some tests here]
gtest_main.cpp:
#include <stdio.h>
#include "gtest/gtest.h"
GTEST_API_ int main(int argc, char **argv) {
printf("Running main() from gtest_main.ccn");
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
我还有一个制作文件,其中包含(除其他外(:
INCLUDES = -I/home/my_username/Documents/gtest/googletest/googletest/include
[...]
$(MAIN): $(OBJS)
$(CC) $(CFLAGS) $(INCLUDES) -o $(MAIN) $(OBJS) $(LFLAGS) $(LIBS)
在终端中写入make
后,我得到:
test_factorial.cpp:1:25: fatal error: gtest/gtest.h: No such file or directory
compilation terminated.
makefile:27: recipe for target 'test_factorial.o' failed
问题出在哪里?
在googletest的自述文件中,他们说:
g++ -isystem ${GTEST_DIR}/include -pthread path/to/your_test.cc libgtest.a
-o your_test
所以这里是-isystem
而不是-I
但我在 -isystem 方面也有问题。
您已将包含添加到链接命令中,但未添加到编译命令中。 此规则:
$(MAIN): $(OBJS)
$(CC) $(CFLAGS) $(INCLUDES) -o $(MAIN) $(OBJS) $(LFLAGS) $(LIBS)
讲述如何从目标文件链接主程序。 此规则不用于编译目标文件:假设您的[...]
没有选择编译规则,则您使用的是内置编译器规则,该规则对INCLUDES
变量一无所知。
如果您在收到该错误时向我们展示编译命令打印test_factorial.cpp
那么很明显该标志丢失了。
如果您不组成自己的变量来保存这些标志,而是使用 CPPFLAGS
变量,这是 C 预处理器标志(如 -I
(的标准变量,它将正常工作。
CPPFLAGS = -I/home/my_username/Documents/gtest/googletest/googletest/include
它可能只是工作。
相关文章:
- CMake导出的库-在客户端应用程序中找不到include/Lib路径
- GNuPlot.exe找不到用于用 C++ 编写的路径
- 找不到 windows.winmd – 如果指定了路径,错误会乘以
- 运行可执行文件时找不到共享库,即使共享库存在于指定的路径中
- 为什么 cmake findBoost 找不到系统提升路径?
- C++流找不到相对路径
- 错误53:找不到文件,而是路径中存在所有DLL
- 使用Cmake时,Emscripten找不到全局路径
- Xmllint未设置,而在路径中找不到XMLLINT;跳过XML预处理
- 在英特尔C++编译器 (Linux) 的配置搜索路径中找不到文件可执行文件
- 即使定义了搜索路径,也找不到自定义共享库
- Windows找不到DLL在路径中的目录中以为其
- makefile 找不到来自 -I 包含路径的头文件
- VS2012:“找不到资源编译器DLL.请确保路径正确.”
- Maven NAR插件:在路径上找不到DLL依赖项
- G++ 找不到库,除非它是完整路径
- 在 Visual C++ 系统调用的路径中找不到可执行文件
- 加速安装失败:系统找不到指定的路径
- 路径正确,但找不到包含
- 为什么Qt Creator在包含的路径中找不到包含的标头 - 即使qmake能够找到它们