Error "A definition for the symbol X could not be loaded" is thrown for variables that use macros in their definition

Mihai Sterpu 1 Reputation point
2022-09-07T15:28:43.42+00:00

Hi,
We have a larger C console project which I recently moved to Visual Studio in order to make our life easier when it comes to debugging.
I have encountered the following problem for all our internal variables which use macros in their definitions.

238722-image.png

Basically, if I hold CTRL and left click on variable Xcp_MemoryWrite I get this error message. This happens also when I right click the variable and choose "Go to definition", "Go to declaration" or "Peek definition".
The problem disappears as soon as I remove the macro from the variable definition:

238567-image.png

With this definition I can jump to the definition of Xcp_MemoryWrite variable from anywhere in our code.

VAR is actually defined as

#define VAR(a,b) a b  

I first suspected this might be related to the VAR macro so I tried to reproduce it on a smaller scale project.
Therefore, I tried to create an empty project with a similar code:

238733-image.png

BUT I cannot reproduce the behaviour I experience in my large project :(
For instance, when I CTRL + click on myVar at line 28 VS jumps to line 23 where the definition is.

So on the small project, when the variable is defined with the VAR macro, Visual Studio behaves correctly but on the larger project it doesn't.

Can somebody help me understand what's the problem in my large project? Or at least give me some hints in order to further debug this?

What I already tried so far:

  • manually remove the .svn hidden folder at the root of my solution
  • re-building and rescan solution

I'm using Visual Studio 2017 Version 15.9.35

Developer technologies | Visual Studio | Other
{count} votes

1 answer

Sort by: Most helpful
  1. Mihai Sterpu 1 Reputation point
    2022-09-07T19:42:07.85+00:00

    Ok found the problem myself :)
    Short answer: https://learn.microsoft.com/en-gb/cpp/build/reference/hint-files?view=msvc-170
    Long answer: the VS parser is a fuzzy parser thus it cannot fully parse everything.
    It requires manual intervention in case certain parts of the code use macros.
    In my case, because I used the VAR macro, the parser basically ignored this line. This was already reported via "Display browsing database errors" option when I right clicked the project.

    In order to fix it I added a file called cpp.hint under the same directory as the one which contained the source file where the variable was defined. Inside this hint file I added the following code:

    #define STATIC static  
    #define XCP_VAR_CLEARED  
    #define VAR(a,b) a b  
    

    After I done this I closed and re-opened the solution and the problem was gone!

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.