Eclipse CDT shows semantic errors, but compilation is ok

后端 未结 20 1391
青春惊慌失措
青春惊慌失措 2020-12-01 07:42

I have installed Eclipse Indigo for C/C++ Linux developers on Ubuntu 10.04 x86.

When I use common predefined macro __BASE_FILE__ Eclipse says Sym

相关标签:
20条回答
  • 2020-12-01 08:14

    The problem occurs this way: I insert a new variable name into the code somewhere e.g. "newone" in this example:

    int a;
    
    foo()
    {
      a=17;
      newone=23;
    }
    

    The file is saved (so the indexer is reindexing). Then I added the definition:

    int a, newone;
    
    foo1()
    {
      newone=0;
    }
    
    
    foo()
    {
      a=17;
      newone=23;
    }
    

    The indexer will still shows the error at the line " newone=23;" but not at the other lines of code containing "newone".

    Solution: first define your variables, then use it.

    M.

    0 讨论(0)
  • 2020-12-01 08:17

    try this:

    Preferences --> c/c++ --> Indexer --> Index all header variants

    check this option.

    0 讨论(0)
  • 2020-12-01 08:17

    I used #pragma once in my code. This configuration caused me to have the problem:

    ---fileA.h---

    #pragma once
    #define MYMACRO(X) func(X)
    

    ---fileB.h---

    #include "fileA.h"
    

    ---fileB.cpp---

    #include "fileB.h"
    
    MYMACRO(5)  <---- warning here
    

    I replaced #pragma once with #ifndef #define HEADER_FILE_H #endif, and that fixed the problem.

    0 讨论(0)
  • 2020-12-01 08:21

    I personally agree with compostus' answer.

    It's good to solve the real problem that eclipse's code analyzer have.

    But when I try this steps: define the symbol in Project -> Properties->C/C++ General -> Paths and Symbols

    I don't find symbol tab or any place to add a symbol. what I want to do is putting macros like -DANDROID or #define ANDROID 1 to eclipse so that the code analyzer can find this definition.

    I'm under Mac OSX mountain lion.

    0 讨论(0)
  • 2020-12-01 08:24

    You need to rebuild the index of your project.

    Right-click on the project, then Index->Rebuild.

    0 讨论(0)
  • 2020-12-01 08:24

    Not sure if this works for the OPs issue, but I had semantic errors in eclipse Luna and was able to resolve them by following instructions in this thread: Eclipse shows unresolved inclusion but it compiles

    The compiler finds the header, but Eclipse not.

    You could help Eclipse and set the path to the header files under:

    Project -> Properties -> C/C++ Build -> Settings -> Compiler -> Includes

    In my situation, eclipse had determined one of my include directories, but did not determine that there were sub-include directories within it.

    0 讨论(0)
提交回复
热议问题