【问题标题】:g++ can't find headers even when it's specified即使指定了标题,g ++也找不到
【发布时间】:2012-12-18 17:24:40
【问题描述】:

所以基本上我有一些非常简单的代码,包括位于/Users/wen/Projects/include/bigint 中的<BigIntegerLibrary.hh>。我正在用这个编译:

g++ main.cpp -o Main -I/Users/wen/Projects/include/bigint

但它报告了一个无法找到文件的致命错误。我做对了吗?谢谢!

main.cpp:4:10: fatal error: 'BigIntegerLibrary.hh' file not found

【问题讨论】:

  • 你试过绝对路径吗?
  • 是的,我有,它有效,但我不知道为什么它不能。
  • @TrevorHickey 这不是他刚刚展示的吗?
  • 执行ls /Users/wen/Projects/include/bigint/BigIntegerLibrary.hh 并在此处输入结果
  • 尝试详细模式,也许它会告诉一些提示

标签: c++ g++ makefile


【解决方案1】:

试试

#include "BigIntegerLibrary.hh"

如果您使用尖括号 (#include <includeFile.h>) 指定 #included 文件,编译器将尝试在预定义的位置找到它,而如果您使用 #include "includeFile",编译器首先会尝试您设置的路径使用 -I 编译器选项指定。

-I 编译器选项不能用于指定<...> 文件的位置。

【讨论】:

  • 您确定路径中字母的大小写对吗?您是否仔细检查了ls /Users/wen/Projects/include/bigint/BigIntegerLibrary.hh
  • 是的,仔细检查。当我在路径上执行cat 时,它显示了内容。
  • -我可以更改 <...> 文件的位置,它会修改搜索路径。证据:手册,并且它适用于我的系统。
【解决方案2】:

如果路径正确,g++ 应该会看到文件。

如果你在include指令中使用绝对路径,你应该改变引号:

#include "/Users/wen/Projects/include/bigint/BigIntegerLibrary.hh"

【讨论】:

  • 我在使用 absolute 时确实更改了它,但现在如果我使用任何类型的括号,当我使用 -I 时它将不起作用。
  • 仔细检查路径;如果正确且可读,它应该可以工作
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-10
  • 1970-01-01
  • 1970-01-01
  • 2021-10-22
相关资源
最近更新 更多