26

So I am building some Arduino code in eclipse, as described in Your Second Arduino Project, but every time I use an Arduino library, such as Serial, Eclipse underlines my function names, claiming they cannot be resolved. However, the code actually compiles, so I'm kind of at a loss as to why Eclipse thinks the functions are missing. If anyone has any idea on how to solve this problem it would be appreciated. Thanks beforehand.

EDIT: I should have been more specific, Eclipse underlines the METHODS inside the Arduino libraries. So if I use Serial.println("hello");, it underlines println() and claims it cannot be resolved. Then it compiles just fine and the method works when uploaded to the arduino board.

EDIT2: I found my error, turns out I was trying to use some C++ functions in a C file, and eclipse didn't like it; I renamed to .cpp and all the red disappeared ;) Thanks for your help!

SuperTron
  • 4,203
  • 6
  • 35
  • 62
  • Does it keep underlining them even after you compile? – Kiril May 11 '12 at 15:25
  • Hmm, well that's unfortunate! I'm not sure what could be causing that. – Kiril May 11 '12 at 15:29
  • Is the code compiling within eclipse, or externally? If it's compiling externally, it could just be a missing library definition within the IDE... – atk May 11 '12 at 15:30
  • It should be compiling in eclipse with the eclipse AVR plugin. That does mean it is using avr-gcc/avr-g++ though, if that's what you mean by "external". – SuperTron May 11 '12 at 15:32
  • I had this problem and I just needed to re-index! This worked for me: https://stackoverflow.com/a/10554556/4561887 – Gabriel Staples Mar 20 '18 at 05:40

9 Answers9

42

Eclipse may or may not be pulling the paths to index from your build setup, depending on the configuration. Most likely, it is not...it's building correctly because your build setup is just fine, and you can probably build by hand.

The CDT indexer (which is the engine for deciding where all those pretty underlines, as well as code completion, F3 declaration jumping, etc comes from) isn't smart enough in a lot of cases to parse out your Makefiles and know where to look for headers and source. You need to tell Eclipse that information manually.

Go to Project Properties -> C/C++ General -> Paths and Symbols.

The amount of work you need to put into this can vary greatly, depending on your environment. If this external library is the only thing giving you headaches, then you probably just need to add the paths for that library and reindex:

Right-click on the project and select Index -> Rebuild

dolphy
  • 6,218
  • 4
  • 24
  • 32
9

For starters, what color is the underline? This makes a difference, as yellow means it's a warning, and red means it's an error (critical, will not build in most circumstances).

Second, you need to look at the "Problems" tab to see if there are actual errors. If there is nothing there, then it did indeed compile correctly.

Now, back to the original question. Depending on the type of project you are building, this type of behavior is not that uncommon. Eclipse seems to do a poor job of indexing certain projects. When you run "make all" from the command line (which is effectively what Eclipse does during build) it is likely resolving all of your code and building it just fine.

However, Eclipse uses a different, separate tool for indexing all of your source code and resolving variable/function definitions and declarations. This is literally a case of the left hand not knowing what the right hand is doing.

Cloud
  • 18,753
  • 15
  • 79
  • 153
  • 4
    All the underlines are red, and my problems tab says they are all "Semantic Errors". As amusing as it is to successfully compile a file that is entirely red, is there some way to at least hide all these red lines? :P – SuperTron May 11 '12 at 15:38
6

The solution below worked for me: Click to your project using right click. Then: Properties -> C/C++ General -> Paths and Symbols -> Symbols -> GNU C++. Almost for sure there are no symbols at all if you have this problem. Add symbol "__cplusplus" with value "201402L" After this: Right click on Project -> Index -> Rebuild You are done.

Community
  • 1
  • 1
Zormex
  • 61
  • 1
  • 3
1

I had include folders in

Project Properties -> C/C++ General -> Paths and Symbols -> Includes

When I removed those, the red underlines went away, i.e. the build and the IDE where in sync.

robor
  • 2,969
  • 2
  • 31
  • 48
1

When resolving symbols, CDT indexer seems to consider all header files irrespectively of which ones are actually included in the compilation unit. There is a corresponding bug report filed with Eclipse Bugzilla: https://bugs.eclipse.org/bugs/show_bug.cgi?id=439553

Compfy
  • 21
  • 1
1

In my case the problem was due to adding "-std=c++17" flag in the language standard field in the project properties under the compile dialect. After that the build was passing with errors, but the program was running fine. So the trick of Index>Rebuild resolved everything.

Hack06
  • 963
  • 1
  • 12
  • 20
  • Thank you! Is there some way to actually compile with a specific standard? – Al G Johnston Dec 15 '21 at 23:05
  • @AlGJohnston, if I understood your question well, you can compile with any standard by replacing the ```c++17``` in my given case for the ```-std=``` compilation flag. – Hack06 Dec 16 '21 at 18:50
1

If you changed something in the configurations, (example, editing in *.cproject file with notepad++) , the below options helps. Build Configurations --> Clean All and then Index --> Rebuild

0

I had the same problem. Index -> Rebuild didn't help. When I added line #include <avr/iom1280.h> in main.cpp and made Index -> Rebuild underlines dissapeared. Then I deleted line #include <avr/iom1280.h> and project still without inderlines.

Replace iom1280.h with name of your controller. Look at the "avr\include\avr\" folder for available names

Petro Shm
  • 339
  • 2
  • 10
  • 1
    Not an ideal solution. Does this for you during compile and bases it on the MCU you specify to the compiler. – Larcho Oct 06 '17 at 14:22
0

Eclipse does not work as well with C++ as it does with Java, but it should warn you about issues once you press "Rebuild" in the menu bar.

Try that, and see if it resolves your problem.

Enusi
  • 101
  • 1
  • 5