g++ can't find headers even when it's spec

2019-03-30 21:21发布

So basically I have some really simple code that includes <BigIntegerLibrary.hh> which resides in /Users/wen/Projects/include/bigint. I was compiling with this:

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

but it reported a fatal error that it could not find the file. Am I doing it right? Thanks!

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

标签: c++ g++ makefile
2条回答
聊天终结者
2楼-- · 2019-03-30 22:01

Try

#include "BigIntegerLibrary.hh"

If you specify the #included file with angle brackets (#include <includeFile.h>) the compiler will try to find it in a predefined location whereas if you use #include "includeFile" the compiler first tries the paths you specified with the -I compiler option.

The -I compiler option cannot be used to specify where the <...> files are.

查看更多
Evening l夕情丶
3楼-- · 2019-03-30 22:02

If the path is correct g++ should see the files.

If you use absolute path in include directive, you should change quotation:

#include "/Users/wen/Projects/include/bigint/BigIntegerLibrary.hh"
查看更多
登录 后发表回答