Visual Studio 2013 fatal error C1041 /FS

Viewed 59954

I'm using Visual Studio 2013. Every so often by project refuses to compile. If I undo any changes, it still won't compile. I've found that recreating the entire project works. I would like to actually fix the problem though. The error that I'm getting is:

1>Critic.cpp : fatal error C1041: cannot open program database 'c:\users\username\desktop\projectName\projectName\x64\debug\vc120.pdb'; if multiple CL.EXE write to the same .PDB file, please use /FS

I've tried following these instructions to no avail: http://msdn.microsoft.com/en-us/library/dn502518.aspx

Has anyone else encountered this and found a fix?

24 Answers

I had the same issue with vs2017 generated with cmake. I tried adding /FS to both CMAKE_C_FLAGS and CMAKE_CXX_FLAGS but it didn't help. I did not want to sacrifice multi-processor compilation because I have a fairly large project and I want my project built as fast as possible using all the cores available on my PC.

So instead, I opted to switch cmake's default debug flag /Zi to /Z7 which embeds the debug symbols into the .obj (similar to how GCC/Clang works) instead of creating an external .pdb. It worked for me.

    STRING(REGEX REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
    STRING(REGEX REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")

Please be aware that using /Z7 will make your binary significantly larger.

I had the same problem and the Intermediate directory was empty for that project. So the accepted fix did not work for me.

I fixed it by doing a clean and build on the project that gave the error

I ran into this issue while building in Qt Creator with MSVC. Creating the missing debug folder and rebuilding fixed the issue.

I was trying to build on a docker volume. It seems that cl.exe cannot handle mapped directories. I copied the files to a non-mapped folder and it compiled successfully.

One of the reasons why this error may occur is that pdb files are marked with a read-only attribute. If they are, remove the read-only attribute from the file.

To remove Right Clik on PDB File -> Properties -> Uncheck Attributes: ReadOnly

I had this problem on several projects. On those projects I had <ProgramDataBaseFileName> set under the <ClCompile> section. Removing the <ProgramDataBaseFileName> section and its tag (so that Visual Studio uses the default) made this go away.

I had a similar issue. I couldn't even delete the pdb files of my project. Windows told me that the application serviceHub.Host.CLR.x64 accessed these files. This process is used by Visual Studio although Visual Studio was restarted.
Killing this process helped!

Related