Skip to content

Instantly share code, notes, and snippets.

@gavinb
Created June 22, 2020 05:53
Show Gist options
  • Save gavinb/6caf815f376c37b6c0cf32587d6ae8e0 to your computer and use it in GitHub Desktop.
Save gavinb/6caf815f376c37b6c0cf32587d6ae8e0 to your computer and use it in GitHub Desktop.

The Visual Studio compiler generates and modifies many large project-wide binary files during compilation, so normally you can only have one instance of cl running per project. If you use the awesome Ninja tool, it will happily run many instances in parallel on multicore systems. When run this way however, MSVC will throw errors like this:

fatal error C1041: cannot open program database 'sample_project_pathname.pdb';
if multiple CL.EXE write to the same .PDB file, please use /FS

To avoid these annoying errors, add the following to your top-level CMakeLists.txt script to enable strict file locking:

if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
	if(CMAKE_GENERATOR MATCHES "Ninja")
		SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /FS")
	endif()
endif()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment