user1935361
user1935361

Reputation: 442

GCC can't find header file with -I option specified

I have this source file

//src.c
#include "include/headers/my_header.h"

And gcc fails with this error include/headers/my_header.h: No such file or directory

gcc my_src/src.c -Iinclude/headers

However, it works fine if I rewrite the source file like so:

//src.c
#include "my_header.h"

Now, I'm actually compiling a project I've inherited so I'm not trying to rewrite all of the include statements. What gives?

Upvotes: 1

Views: 5161

Answers (1)

Cris Luengo
Cris Luengo

Reputation: 60444

The path after -I catenated to whatever is in the #include statement has to match a path in your file system. Try -I., that leads to ./include/headers/my_header.h, and presumably will let GCC find your header.

Upvotes: 1

Related Questions