DEV Community

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

Posted on

4 1

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": [
        "-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake"
    ],
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.

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay