Search code examples
includeeclipse-cdteclipse-luna

Eclipse CDT, how to make it NOT search for system headers?


I'm porting a C project compiled on linux to an arm platform using Eclipse Luna on Ubuntu 16.04

When I switch from CC=gcc to CC=arm-none-eabi in the Makefile I get a lot of missing headers and that's ok, that's what the porting job is about.

What bothers me is that when I CTRL-click on a symbol Eclipse doesn't open the corresponding file for the arm toolchain. For instance if I CTRL-click on <time.h> it does NOT open:

/media/BUILDS/arm_gcc493/arm-none-eabi/include/time.h

but instead it always reverts to its linux system counterpart, in this case

/usr/include/i386-linux-gnu/time.h

because that's where gcc would look for but I'm compiling with arm-none-eabi-gcc instead!

I don't want Eclipse to do that because debugging gets really confusing. If I have a problem with the header/source I'm actually trying to compile with, I want Eclipse to open me that file and not the default system one. I fiddled with Project Properties and Eclipse Preferences but with no luck.

Even worse, whenever <sys/socket.h> is included I get an error because the arm toolchain does not have socket.h but if I CTRL-click on it Eclipse takes me to /usr/include/i386-linux-gnu/sys/socket.h

I dont' want that, if the header needed for compilation is not there, it's just not there. I don't want Eclipse to show me other stuff, how do I do that?

The project was created importing into the workspace "Existing Code as Makefile Project" under C/C++

Thank you very much

EDIT:

I did the proper thing and started from scratch creating a project for the Cross ARM GCC Toolchain (with the proper plug-in). My mistake was creating a "Linux GCC" Project and pretending that Eclipse understood what I was trying to achieve just by launching a different "make" command. If, however, you can't restart from scratch, the accepted solution instructs you on how to fix the situation manually.


Solution

  • To resolve this situation you need to update the Preprocessor Include Paths, Macros, etc. setting to use your custom-prefix GCC.

    To make the change:

    1. Open Project Properties (Right-click on project and choose Properties)
    2. In C/C++ General -> Preprocessor Include Paths, Macros, etc., choose Providers tab
    3. Select CDT GCC Built-in Compiler Settings
    4. Uncheck Use global provider shared between projects
    5. Replace ${COMMAND} with arm-none-eabi-gcc or arm-none-eabi-g++

    Alternatively, you can also edit the same setting at the workspace level to affect all the projects in your workspace. Go to Window -> Preferences -> C/C++ -> Build -> Settings -> Discovery tab instead.

    Here are some screenshots that may help.

    Before:

    before

    Project Properties:

    project properties

    After:

    after