Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Error "Symbol 'pair' could not be resolved" when using typedef(Why does using "typedef struct <blah>" show an error with std::map but using "struct <blah>" does not)
Error "Symbol 'pair' could not be resolved" when using typedef [message #1829285] Tue, 30 June 2020 13:25 Go to next message
Dave Rathnow is currently offline Dave RathnowFriend
Messages: 25
Registered: March 2014
Junior Member
OS: Ubuntu 18.04
Eclipse Version: 2020-03 (4.15.0)
Build id: 20200313-1211
CDT: 9.11
Project: C/C++ with self-managed makefile

I create two files: foo.h and foo.cpp:

foo.h:
#ifndef FOO_H_
#define FOO_H_

#include <stdint.h>

typedef struct
{
    uint8_t dataType;
    uint16_t offset;
    uint32_t ioId;
} header_t;

#endif 


foo.cpp:
#include "foo.h"
#include <map>

using namespace std;

int main(int argc, char **argv)
{
    header_t header;
    map<uint32_t, header_t> theMap;

    theMap.insert(pair<uint32_t, header_t>(1, header));
}


When I open foo.cpp in CDT editor, the editor displays a red line under
theMap.insert(pair<uint32_t, header_t>(1, header))
             ^-----------------------^

When I mouse over the line, the editor shows the error "Symbol 'pair' could not be resolved" and yet the file compiles fine.

However, if I put everything into a single file

#include <map>
#include <stdint.h>

typedef struct
{
    uint8_t dataType;
    uint16_t offset;
    uint32_t ioId;
} header_t;

using namespace std;

int main(int argc, char **argv)
{
    header_t header;
    map<uint32_t, header_t> theMap;

    theMap.insert(pair<uint32_t, header_t>(1, header));
}


I get no error and everything still compiles. I've also noticed that if I change my typedef to

typedef struct _header_t
{
    uint8_t dataType;
    uint16_t offset;
    uint32_t ioId;
} header_t


or just use 'struct', and my map declaration to

    header_t header;
    map<uint32_t, _header_t> theMap;

    theMap.insert(pair<uint32_t, _header_t>(1, header));


I get no errors in the editor and everything still compiles.

What quirk in the editor is causing this? Is there a way to fix this so it doesn't display the red line?

Re: Error "Symbol 'pair' could not be resolved" when using typedef [message #1829297 is a reply to message #1829285] Wed, 01 July 2020 06:02 Go to previous messageGo to next message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
Since you haven't told us how your project is structured or how it was constructed, we can only guess what the cause is.

By "self-managed makefile" I assume you mean a Makefile project vs. a Managed Build project.
It appears the Indexer doesn't know how to find foo.h
At least that's what happened when I had foo.h in a directory named inc
When I moved it to the src directory where the .cpp is stored, everything was resolved after the Indexer had run.

FWIW I tested this with 2020-06

There are a number of ways to inform the Indexer where header files are located.
The Indexer uses the information found in
Project --> Properties --> C/C++ General --> Preprocessor Include Paths, Macros etc.
which can be populated manually or via various providers.

I moved foo.h back into inc
then told the Indexer to look there.
This also worked.

index.php/fa/38454/0/

[Updated on: Wed, 01 July 2020 06:17]

Report message to a moderator

Re: Error "Symbol 'pair' could not be resolved" when using typedef [message #1829343 is a reply to message #1829297] Wed, 01 July 2020 16:02 Go to previous messageGo to next message
Dave Rathnow is currently offline Dave RathnowFriend
Messages: 25
Registered: March 2014
Junior Member
David,

Thanks for the reply but this isn't an issue with the indexer not finding my include file. I can put other declarations in the include file and the indexer finds them fine.

To illustrate my point, I created a new empty "C++ Managed Build" project and dropped foo.h and foo.cpp into the project directory. I then modified them as shown below. The files compile fine but Eclipse editor is still showing me the error, as shown in the attached screenshot.

#ifndef FOO_H_
#define FOO_H_

#include <stdint.h>

typedef struct
{
    uint8_t dataType;
    uint16_t offset;
    uint32_t ioId;
} header_t;

struct header {
    uint8_t dataType;
    uint16_t offset;
    uint32_t ioId;
};

#endif

#include "foo.h"

#include <map>

using namespace std;

int main(int argc, char **argv)
{
    struct header structHeader;
    header_t typedefHeader;
    map<uint32_t, struct header> structHeaderMap;
    map<uint32_t, header_t> typedefHeaderMap;

    structHeaderMap.insert(pair<uint32_t, struct header>(1, structHeader));
    typedefHeaderMap.insert(pair<uint32_t, header_t>(1, typedefHeader));
}

index.php/fa/38463/0/
Re: Error "Symbol 'pair' could not be resolved" when using typedef [message #1829381 is a reply to message #1829343] Thu, 02 July 2020 11:04 Go to previous messageGo to next message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
Well, it works for me so your configuration is somehow different.
I guessed the indexer wasn't finding the include because you said: " if I put everything into a single file I get no error ".
Why is that?
Something is causing the Indexer to ignore the include.

Getting a parser log may reveal why.

[Updated on: Thu, 02 July 2020 11:06]

Report message to a moderator

Re: Error "Symbol 'pair' could not be resolved" when using typedef [message #1829443 is a reply to message #1829381] Fri, 03 July 2020 15:31 Go to previous messageGo to next message
Dave Rathnow is currently offline Dave RathnowFriend
Messages: 25
Registered: March 2014
Junior Member
Thanks again for your reply, however, I must respectfully disagree. The indexer is finding the include file as is apparent from my screen shot that shows no errors for the other declarations in that file. The indexer seems to be having problems with the typedef used with the STL map container or, more specifically, the "pair" template.

Another interesting twist to this is that I can make the error go away if I add a name into the typedef like this:

typedef struct _header_t
{
    uint8_t dataType;
    uint16_t offset;
    uint32_t ioId;
} header_t;


It is curious that you do not see the problem. Could you share your OS, Eclipse, and CDT versions? How can I generate a parse log?

Re: Error "Symbol 'pair' could not be resolved" when using typedef [message #1829446 is a reply to message #1829443] Fri, 03 July 2020 16:31 Go to previous messageGo to next message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
Eclipse Version: 2020-06 (4.16.0)
Build id: 20200615-1200

CDT Version: 9.11.1.202006011430
Build id: 20200601-1605

OS: 5.2.15-200.fc30.x86_64 (Fedora)
OpenJDK Runtime Environment (build 1.8.0_222-b10)

Again, you indicated that putting things in the same file also solves the problem.
Why would it occur only when placed in two files?
Have you tried rebuilding the index?
Is the Index tied to a specific build configuration?

FWIW: being able to compile (you've said this more than once) only indicates you've adhered to legal syntax otherwise it has nothing to do with the Indexer.

Quote:
Another interesting twist to this is that I can make the error go away if I add a name into the typedef.

What happens when you remove the name?


Re: Error "Symbol 'pair' could not be resolved" when using typedef [message #1829475 is a reply to message #1829446] Sat, 04 July 2020 14:24 Go to previous messageGo to next message
David Wegener is currently offline David WegenerFriend
Messages: 1445
Registered: July 2009
Senior Member
Is it possible that header_t symbol is declared somewhere else in either your code or in one of the header files (either directly included by your code or in the include chain). This might explain the differing behavior depending on the code being directly in the .cpp file vs being pulled in from an include file.

Have you tried a test of changing the name to something other than header_t (my_header_t, bob, thisisunique, etc). If you can get another name to work, it might give a clue as to where a possible conflict might be.
Re: Error "Symbol 'pair' could not be resolved" when using typedef [message #1829604 is a reply to message #1829475] Tue, 07 July 2020 13:56 Go to previous messageGo to next message
Dave Rathnow is currently offline Dave RathnowFriend
Messages: 25
Registered: March 2014
Junior Member
That's not the case. I have a project that only has three file: foo.h, foo.cpp, and bar.cpp. I still get the error.

If you would like to see what the project looks like, I have attached it as a tarball. I would be interested to see if you, or anyone else, has the same problem that I'm having.
Re: Error "Symbol 'pair' could not be resolved" when using typedef [message #1829605 is a reply to message #1829446] Tue, 07 July 2020 13:56 Go to previous messageGo to next message
Dave Rathnow is currently offline Dave RathnowFriend
Messages: 25
Registered: March 2014
Junior Member
Quote:

What happens when you remove the name?


See my original post.

[Updated on: Tue, 07 July 2020 14:07]

Report message to a moderator

Re: Error "Symbol 'pair' could not be resolved" when using typedef [message #1829627 is a reply to message #1829605] Tue, 07 July 2020 22:25 Go to previous messageGo to next message
David Wegener is currently offline David WegenerFriend
Messages: 1445
Registered: July 2009
Senior Member
Symbol lookup isn't limited to the files in your project. It extends to any files your code includes. You have includes for stdint.h and map at a minimum. These header files will include additional header files. These create a chain of include files that are all used by the compiler to locate symbols. If header_t exists as a symbol any where in the include chain, it can cause problems when you compile your code.
Re: Error "Symbol 'pair' could not be resolved" when using typedef [message #1829628 is a reply to message #1829627] Tue, 07 July 2020 22:33 Go to previous message
Dave Rathnow is currently offline Dave RathnowFriend
Messages: 25
Registered: March 2014
Junior Member
Thanks and yes, I understand all that and I've done the searching to make sure there are no other typedefs in any of the includes I've used (or the ones they use) with that name. Still, even with an explicit namespace in the declaration (i.e. pair<uint32_t, foo::header_t>), it still shows an error.

I should also add that if it were a clash of names, the project wouldn't compile and that's not the case. The project does build.

[Updated on: Tue, 07 July 2020 22:35]

Report message to a moderator

Previous Topic:Assembly file(.S) compilation fails.
Next Topic:org.eclipse.cdt.ui contributed an invalid Menu Extension
Goto Forum:
  


Current Time: Thu Apr 25 01:37:15 GMT 2024

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

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

Back to the top