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
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"
],
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 (2)
If you're using VS Code with CMake to build a Linux project via WSL2 or SSH and run into issues with CMAKE_TOOLCHAIN_FILE pointing to a Windows path, the culprit might be a global setting in your %APPDATA%\Code\User\settings.json. In my case, a lingering -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake entry was being applied to all builds, including remote ones—causing obvious compatibility errors. Simply removing that entry and clearing CMakeCache.txt fixed the problem. Just like with Little Nightmares 2 Complete Game, where a small overlooked detail can ruin the entire experience, a hidden config in your toolchain setup can derail your build—so check those global settings first.
Some comments may only be visible to logged-in visitors. Sign in to view all comments.