Skip to main content



      Home
Home » Language IDEs » C / C++ IDE (CDT) » Editor shows "Symbol could not be resolved" although declared(Symbols which are declared in included files, are not resolved. Compilation succeeds.)
Editor shows "Symbol could not be resolved" although declared [message #1701272] Fri, 10 July 2015 07:54 Go to next message
Eclipse UserFriend
Hello,
I have a problem with the C++ indexer (Eclipse Luna CDT).
My test project contains two files: main.cpp and createSomething.h (see below)
The Editor doesn't recognize that the symbol "something" is declared in the preprocessor directive '#include "createSomething.h':
index.php/fa/22492/0/

If I declare the object directly in main.cpp instead of using "#include...", the error disappears.

How can I configure CDT so that it understands symbols declared in included files?

main.cpp:
class Something{
public:
  Something(){ }
  void run(){ }
};

int main(int argc, char** argv){
    #include "createSomething.h"
	//Something something;

	something.run();
}


createSomething.h :
Something something;


Thanks
Peter
  • Attachment: cdt.png
    (Size: 26.15KB, Downloaded 1416 times)
  • Attachment: cdt.png
    (Size: 26.15KB, Downloaded 180 times)

[Updated on: Tue, 14 July 2015 04:19] by Moderator

Re: Editor shows "Symbol could not be resolved" although declared [message #1701382 is a reply to message #1701272] Mon, 13 July 2015 03:52 Go to previous messageGo to next message
Eclipse UserFriend
Nobody?
If this is a FAQ entry, I have no problem with an answer like "RTFM", but please give a link, where I can find the ... manual.

Thanks
Peter
Re: Editor shows "Symbol could not be resolved" although declared [message #1701593 is a reply to message #1701382] Tue, 14 July 2015 06:46 Go to previous messageGo to next message
Eclipse UserFriend
Your code in main.cpp looks strange. #include usually comes before anything else. Your .h file should contain the class declaration. There are many cpp tutorials available.
Re: Editor shows "Symbol could not be resolved" although declared [message #1701598 is a reply to message #1701593] Tue, 14 July 2015 07:15 Go to previous messageGo to next message
Eclipse UserFriend
Geoff Kaniuk wrote on Tue, 14 July 2015 10:46
Your code in main.cpp looks strange. #include usually comes before anything else. Your .h file should contain the class declaration. There are many cpp tutorials available.


#include can go anywhere. Many projects exist that use this kind of #includes just to move chunks of the code into separate files. I know that this is not recommended, but I would like the Eclipse editor to show code completion in this situation instead of errors.

(Unfortunately I confused "declare" and "define" in my original post. Nevertheless, the example showing the problem is correct. The point is that I am using "#include xyz.h" in order to define objects in some separate file. This is fine for the compiler, but not for the Eclipse editor.)
Re: Editor shows "Symbol could not be resolved" although declared [message #1702860 is a reply to message #1701272] Sun, 26 July 2015 09:13 Go to previous message
Eclipse UserFriend
Apparently it's the placement of the include in main. I could resolve it by placing just before main:

#ifdef __CDT_PARSER__
#include "createSomething.h"
#endif

UPDATE: Just to be clear. you only need to insert the above three lines. No other changes needed.

The indexer is now happy. The "__CDT_PARSER__" is used to surround code that only the indexer can see keeping it hidden from the compiler.

Doing this could cause other problems, of course. Razz

Sorry, but the only link I have for this
https://www.eclipse.org/forums/index.php/t/1068546/

HTH

[Updated on: Sun, 26 July 2015 09:20] by Moderator

Previous Topic:Error while installing AVR Eclipse Plugin in Linux
Next Topic:Changing vector registers in registers view
Goto Forum:
  


Current Time: Mon Jul 07 10:52:00 EDT 2025

Powered by FUDForum. Page generated in 0.05397 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top