Search code examples
c++gcceclipse-cdt

Eclipse Neon: can't find my user-defined class (c++, Linux)


I have a c++ project in Eclipse Neon with Ubuntu 16.04 configured to use opencv. The project seemend to be correctly (i.e: opencv is not the issue :-) ) configured until I created a new class in the project and tried to use it from main. screenshot

The IDE seems to know my class 'Calculaflujos' exists, as the autocomplete features displays a list of the class methods. However, when I try to build the project it says (lower part of screenshot): 'fatal error: Calculaflujos.cpp, no such file or directory'.

I have very little experience with c++ and the make file has been generated by Eclipse.

Any ideas why this might be happening?

Thank you.


Solution

  • A few things going on here:

    1. You should include the .h file from another .cpp file.
    2. You are using <> type includes, which means it will not consider files in the current directory. Either use "" or add src to your include path.

    A concrete little example:

    $ cat a.h
    /* stuff in header file */
    
    $ cat quotes.cc 
    #include "a.h"
    
    $ cat gtlt.cc 
    #include <a.h>
    
    $ g++ -c quotes.cc
    
    $ g++ -c gtlt.cc
    gtlt.cc:1:15: fatal error: a.h: No such file or directory
     #include <a.h>
                   ^
    compilation terminated.
    
    $ g++ -c gtlt.cc -I .
    
    1. Consider the output in the Console view. Sometimes seeing the raw output from the compiler makes sense. It is always very helpful to include that in a question like this too.