“Unresolved inclusion” error with Eclipse CDT for C standard library headers

前端 未结 14 2285
甜味超标
甜味超标 2020-11-28 04:18

I set up CDT for eclipse and wrote a simple hello world C program:

#include 

int main(void){
    puts(\"Hello, world.\");
    return 0;
}
         


        
14条回答
  •  南方客
    南方客 (楼主)
    2020-11-28 04:59

    Also set ${COMMAND} to gcc on Linux

    Under:

    • Project
    • Properties
    • C/C++ General
    • Preprocessor Include Paths, Macros, etc.
    • Providers
    • CDT GCC Built-in Compiler Settings
    • Command to get compiler specs

    Replace:

    ${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"
    

    with:

    gcc -std=c99 -E -P -v -dD "${INPUTS}"
    

    If you don't do this, the Eclipse stdout shows:

    Unable to find full path for "-E"
    

    and logs under ${HOME}/eclipse-workspace/.metadata/.log show:

    !ENTRY org.eclipse.cdt.core 4 0 2020-04-23 20:17:07.288
    !MESSAGE Error: Cannot run program "-E": Unknown reason
    

    because ${COMMAND} ${FLAGS} are empty, and so Eclipse tries to execute the -E that comes next.

    I wonder if we can properly define the COMMAND and FLAGS variables on the settings, but I tried to add them as build variables and it didn't work.

    C++ version of the question: How to solve "Unresolved inclusion: " in a C++ file in Eclipse CDT?

    Tested on Eclipse 2020-03 (4.15.0), Ubuntu 19.10, and this minimal Makefile project with existing sources.

提交回复
热议问题