You might also get this error if you have multiple branches of your project on your development station and use a symlink to point to one of them.
Let's suppose you have two different branches of your solution called Project1
and Project2
and you let a symlink called Project
point to either Project1
or Project2
.
The idea is that you could switch between branches and the project would always appear to be Project
to your application and possibly some other tools that expect it there.
Disclaimer: yes, version control can switch between branches, but this way you will not have to rebuild the whole application every single time you switch branches. Besides both branches can still be under version control.
Okay, so opening Project
would open either Project1
or Project2
depending on the symlink. The symlink could be removed/created by some simple mklink_1
and mklink_2
like script files.
Here comes the pitfall:
If you don't pay attention and directly open the solution at location 1 or 2 directly (instead of following the directory symlink with Visual Studio), the pre-processor might be tricked into mixing Project1\MyHeader.h
(or MyProject2\MyHeader.h
) with MyProject\MyHeader.h
!
Even those are technically the same file, the preprocessor doesn't know about the symlink. So here the #pragma once
would not save you!