DEV Community

Enno Rehling (恩諾)
Enno Rehling (恩諾)

Posted on

Puzzle of the day: VS Code and CMAKE_TOOLCHAIN_FILE

This is one of those problems that I've now solved from scratch at least twice, and never gives good Google result, do it's time I write a post, if only for myself.

My situation is as follows: I'm running VS Code on a Windows host to build a Linux program with WSL2, or other remote connection (i.e. SSH to a remote machine). My build tool of choice is CMake, and I have the CMake extension installed.

Trying to build my project gives me this error:

[proc] Executing command: /usr/bin/cmake --no-warn-unused-cli -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=/usr/bin/x86_64-linux-gnu-gcc-10 -DCMAKE_CXX_COMPILER:FILEPATH=/usr/bin/x86_64-linux-gnu-g++-10 -S/home/enno/echeck -B/home/enno/echeck/build -G "Unix Makefiles"
[cmake] CMake Error at /usr/share/cmake-3.18/Modules/CMakeDetermineSystem.cmake:99 (message):
[cmake]   Could not find toolchain file: C:/vcpkg/scripts/buildsystems/vcpkg.cmake
Enter fullscreen mode Exit fullscreen mode

Somehow, there is a CMAKE_TOOLCHAIN_FILE argument being passed to cmake, and it contains a path on my Windows filesystem (this project also compiles on Windows, using vcpkg for its find_package dependencies). Of course this can't work, I'm using a gcc toolchain on Linux. Where does this come from?

The answer turned out to be that the settings.json file in %APPDATA%\Code\User on my Windows host contained this nugget:

    "cmake.configureArgs": [
Enter fullscreen mode Exit fullscreen mode

I must have set this at some point, trying to use VS Code to build on Windows, and for reasons, VS Code applies it to all my CMake builds, even remote builds. So, after I deleted that entry from the settings.json file and deleted the generated CMakeCache.txt, I can now build my project! And next time this happens, I hope Google will point me to this post.

Top comments (0)