Reputation: 8560
Eclipse: Kepler; CDT: 8.3.0
I just started using Eclipse CDT for a C++ project. I just used UI to add a new empty C++ class and associated header file to the project automatically. Then I press the build button. Build fails. The build scripts Eclipse CDT generated fail due to a simple issue of not setting an include path:
Building file: ../Foo.cpp
Invoking: Cross G++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"Foo.d" -MT"Foo.d" -o "Foo.o" "../Foo.cpp"
../Foo.cpp:8:17: fatal error: Foo.h: No such file or directory
compilation terminated.
make: *** [Foo.o] Error 1
It's building in the subdir Debug/
(that is the default build configuration CDT setup). If I go into the Debug/
dir and just add "-I../" to the g++
command above it works. The build scripts Eclipse CDT creates are failing to find the very source files CDT initialized for me. Why is this failing? Seems really silly. How do I fix it?
Upvotes: 0
Views: 226
Reputation: 1086
A couple things to look at that could be the cause:
#include "Foo.h"
and not #include <Foo.h>
, quotes vs. brackets..h
as in #include "Foo"
..h
file is in the src
folder and not outside of it. Since you said you had to add -I ../
to Debug
than this most likely is your problem. The Foo.h
file is outside of the folder where the rest of your project's .h
files are.It is most likely something simple that was missed. I've run into these little issues in Eclipse on a regular basis.
From your comment it was #1 that was the solution to your problem. If Eclipse is automatically generating #include <Foo.h>
instead of #include "Foo.h"
when it is creating both the .h
and .cpp
for a class then that is a bug with Eclipse.
Upvotes: 1