c++ - 是什么导致 g++ 忽略不存在的目录

标签 c++ linux compiler-errors g++

我正在学习使用 make。我正在尝试在我的家用机器上使用 g++ 编译一个程序,我已经在学校机器上使用 xl 成功编译了该程序。我正在尝试链接我构建并放置在单独目录中的外部库。我试图包含头文件,但 g++ 声称包含目录不存在。 include 目录确实存在,tab complete 会填入它,find 也会找到它。

为什么g++判断目录不存在?通常是什么导致目录被忽略?我想知道为什么这会中断,以便我可以更好地编写 makefile。对我来说更重要的是,我该如何解决这个问题并让 g++ 在我告诉它查找的任何目录中搜索任意头文件?

我看到过关于 g++ 忽略目录的问题,但那些是在忽略各种系统默认位置的情况下。他们通常通过删除冲突版本或重新安装他们的工具来解决问题。我的问题不同,因为 g++ 忽略了实际存在的用户定义目录。

src/a3.cc:1:17: fatal error: apf.h: No such file or directory
#include "apf.h"

$ find /home/USER/Documents/GitHub/core/apf/
/home/USER/Documents/GitHub/core/apf/
/home/USER/Documents/GitHub/core/apf/apfUserData.cc
 ....
/home/USER/Documents/GitHub/core/apf/apf.h

....

我已经尝试使用 -I

在 make 文件中手动指定目录
apf = /home/USER/Documents/Github/core/apf/
CFLAGS = $(CFLAGS) -Wall -g -I $(apf) --pedantic-errors --verbose

我也试过设置 CPLUS_INCLUDE_PATH

export CPLUS_INCLUDE_PATH = $(apf)

对于这些尝试中的每一个,我都看到相同的错误,g++ 是“忽略不存在的目录”

COLLECT_GCC=/usr/bin/g++

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/home/USER/Documents/Github/core/apf/"

ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/4.9.2/include-fixed"
 ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/4.9.2/../../../../x86_64-redhat-linux/include"
ignoring duplicate directory "/usr/local/include"
  as it is a non-system directory that duplicates a system directory
 #include "..." search starts here:
 #include <...> search starts here:
 ./inc
 /usr/lib/gcc/x86_64-redhat-linux/4.9.2/../../../../include/c++/4.9.2
 /usr/lib/gcc/x86_64-redhat-linux/4.9.2/../../../../include/c++/4.9.2/x86_64-redhat-linux
 /usr/lib/gcc/x86_64-redhat-linux/4.9.2/../../../../include/c++/4.9.2/backward
 /usr/lib/gcc/x86_64-redhat-linux/4.9.2/include
 /usr/local/include
 /usr/include
End of search list.
GNU C++ (GCC) version 4.9.2 20150212 (Red Hat 4.9.2-6) (x86_64-redhat-linux)
    compiled by GNU C version 4.9.2 20150212 (Red Hat 4.9.2-6), GMP version 6.0.0, MPFR version 3.1.2, MPC version 1.0.2
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 954ba53e83b294b646fa1b6b73a69682

最佳答案

看来您有一个区分大小写的文件系统。您在某些地方有 GitHub,在其他地方有 Github。让它们都正确匹配,您的体型会更好。

关于c++ - 是什么导致 g++ 忽略不存在的目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29787080/

相关文章:

用于处理 a = b + c 的 C++ 运算符语法,无需显式复制 "a.data_ptr"中的数据

c++ - C++中的空嵌套初始化列表

在 C 中运行 setuid 程序的正确方法

c++ - 编译错误: 'head' does not name a type [duplicate]

android - imageview问题

c++ - Qt - 在 QGraphicsScene 中仅编辑 QGraphicsLineItems

c++ - 从静态方法调用静态函数指针

linux - 在特定时间运行作业

linux - awk 中的用户定义变量

c# - 无法创建变量类型 'Item' 的实例,因为它没有 new() 约束