MantisBT - CMake
View Issue Details
0014492CMakeCMakepublic2013-10-17 16:072014-06-02 08:37
Nick Hutchinson 
Brad King 
normalmajoralways
closedfixed 
WindowsWindows 7
CMake 2.8.12 
CMake 2.8.12.1CMake 2.8.12.1 
0014492: Visual Studio 2013 breaks parallel command-line builds
You get the following error:
fatal error C1041: cannot open program database 'XXXX.pdb'; if multiple CL.EXE write to the same .PDB file, please use /FS

Adding `add_compile_options(/FS)` to a CMakeLists.txt works around the issue, but CMake should probably add it in by default. Infuriatingly, Microsoft don't appear to have documented this flag on MSDN[1].

1: http://msdn.microsoft.com/en-us/library/vstudio/fwkeyyhe(v=vs.120).aspx [^]
With Ninja and Visual Studio 2013 installed (I tested with the Express edition), open a vcvarsall.bat command prompt, and configure and build any CMake project.

E.g.
> cmake -GNinja -DCMAKE_C_COMPILER=cl -DCMAKE_CXX_COMPILER=cl [PATH_TO_SOURCE_TREE]
> ninja -j2
No tags attached.
Issue History
2013-10-17 16:07Nick HutchinsonNew Issue
2013-10-17 16:14Brad KingNote Added: 0034144
2013-10-17 16:20Brad KingNote Added: 0034145
2013-10-17 16:37Nick HutchinsonNote Added: 0034147
2013-10-17 16:43Brad KingNote Added: 0034148
2013-10-18 10:34Brad KingNote Added: 0034156
2013-10-18 10:34Brad KingAssigned To => Brad King
2013-10-18 10:34Brad KingStatusnew => assigned
2013-10-18 10:34Brad KingTarget Version => CMake 3.0
2013-10-18 18:05Peter KuemmelNote Added: 0034169
2013-10-21 09:20Brad KingStatusassigned => resolved
2013-10-21 09:20Brad KingResolutionopen => fixed
2013-10-21 09:20Brad KingFixed in Version => CMake 3.0
2013-11-05 07:44Brad KingFixed in VersionCMake 3.0 => CMake 2.8.12.1
2013-11-05 07:44Brad KingTarget VersionCMake 3.0 => CMake 2.8.12.1
2014-06-02 08:37Robert MaynardNote Added: 0036001
2014-06-02 08:37Robert MaynardStatusresolved => closed

Notes
(0034144)
Brad King   
2013-10-17 16:14   
According to "cl /?":

 /FS force to use MSPDBSRV.EXE
(0034145)
Brad King   
2013-10-17 16:20   
Is there a "/Fd<something>" option in the generated compile command lines? Does it refer to a directory?
(0034147)
Nick Hutchinson   
2013-10-17 16:37   
There is, and it does. Sample error:

FAILED: "C:/opt/cmake/bin/cmcldeps.exe" C y:\the_silver_searcher\third_party\pthread-win32\attr.c "CMakeFiles/pthreadsC2.dir/attr.c.obj.d" CMakeFiles\pthreadsC2.dir\attr.c.obj "Note: including file: " "C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/bin/x86_amd64/cl.exe" C:\PROGRA~2\MICROS~2.0\VC\bin\X86_AM~1\cl.exe /nologo /DWIN32 /D_WINDOWS /W3 /D_DEBUG /MDd /Zi /Ob0 /Od /RTC1 -Iy:\the_silver_searcher\third_party\pthread-win32\. -DHAVE_PTW32_CONFIG_H -DPTW32_ARCH=\"x64\" -DPTW32_RC_MSC -DPTW32_STATIC_LIB /FoCMakeFiles\pthreadsC2.dir\attr.c.obj /FdCMakeFiles\pthreadsC2.dir/ -c y:\the_silver_searcher\third_party\pthread-win32\attr.c
y:\the_silver_searcher\third_party\pthread-win32\attr.c : fatal error C1041: cannot open program database 'c:\dev\ag-ninja\third_party\build\vendor_pthreads_win32\cmakefiles\pthreadsc2.dir\vc120.pdb'; if multiple CL.EXE write to the same .PDB file, please use /FS
(0034148)
Brad King   
2013-10-17 16:43   
Thanks.

Interestingly the IDE project files never seem to build /FS even when using /MP, so it must be that "cl /MP" handles the PDB access itself somehow. It is only when some outside party starts multiple "cl" processes with the same /Fd that this happens (i.e. for sources in the same lib or exe).
(0034156)
Brad King   
2013-10-18 10:34   
This should fix it:

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=216afc8a [^]
(0034169)
Peter Kuemmel   
2013-10-18 18:05   
http://msdn.microsoft.com/en-us/library/vstudio/dn502518.aspx [^]

"The /MP option enables /FS by default."

So adding /FS should be the right fix.
(0036001)
Robert Maynard   
2014-06-02 08:37   
Closing resolved issues that have not been updated in more than 4 months.