简体   繁体   中英

Eclipse can't find include file in subdirectory

After importing a c++ Makefile-project into Eclipse, my project depends on some libraries which are located in /usr/include/gazebo-2.2/gazebo .

These are included via the line #include < gazebo/xx/xx.hh> . CMake doesn't have a problem finding the files, Eclipse unfortunately does...

In my include folder, the folder /usr/include/ is set as include path. However it can't find the include files.

Is it possible for eclipse to discover the files without adding the full path to the include directories?

Is it possible for eclipse to discover the files without adding the full path to the include directories?

Since you are using a Makefile project, presumably your makefile specifies the relevant include path. Eclipse can pick this up using its Build Output Parser. The general way to set this up is:

  1. Make sure your makefile can produce output that includes the full compiler command invocations (eg gcc -I /usr/include/gazebo-2.2 ... - since this is what the build output parser needs to see), or can be configured to produce that output.
  2. Make sure Eclipse is configured to invoke your makefile correctly (in terms of invocation directory and target name) in Project Properties -> C/C++ Build.
  3. Make sure the build output parser is enabled in Project Properties -> C/C++ General -> Preprocessor Include Paths, Macros etc. -> Providers tab. If necessary, adjust the "Compiler command pattern" as appropriate.
  4. Perform a build from within Eclipse. Assuming your build is successful (or at least succesful enough for the build output to contain the compiler commands for every source file), the build output parser should then pick up information such as include paths and macros defined on the command line. In the Project Explorer, source files for which settings were picked up in this way will be annotated with a little wrench decoration on the icon.
  5. At this point, your includes should be resolved. You may need to re-build the index to get Eclipse to process the contents of the newly resolved files.

For completeness, since you mentioned CMake, I'll mention that there also exist plugins that will configure a project's include paths directly based on CMakeLists.txt. (I can't recommend a specific one because I don't use CMake myself, but searching for "CMake" in the Eclipse Marketplace should give you several options.)

Is it possible for eclipse to discover the files without adding the full path to the include directories?

No, not unless the include path in question is one of the compiler's default include paths, which is not so in your case.

If your want the compiler to find the header file referred to by eg

<gazebo/xx/xx.hh>

when the required file is:

/usr/include/gazebo-2.2/gazebo/xx/xx.h

then the compiler must be given the include path:

/usr/include/gazebo-2.2

which should appear in compiler commandlines in your build log as:

-I/usr/include/gazebo-2.2

I notice also that your example is actually:

#include < gazebo/xx/xx.hh>

not:

#include <gazebo/xx/xx.hh>

In your example, the leading space will be considered part of the filename and the header would not be found.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM