Celeb Glow
news | March 27, 2026

CMake can't find source dir when run from bash script in WSL

I'm running the Ubuntu version of Windows Subsystem for Linux. In there I've set up a simple cmake project and created a script to save me from typing out

cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug ../../

every time I want to build. My CMakeLists.txt exists in two directories above (thus ../../). The build works fine if I type the command above manually OR run a powershell script with the exact same command and nothing else.

But running this bash script inside WSL

#!/bin/bash
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug ../../

I receive the error " does not exist.source directory "/mnt/c/dev-files/C/Practice/.

It looks like the bash script messes up the error output of cmake, so I'm guessing the script is executing cmake or passing the arguments incorrectly but I have no idea why.

6

1 Answer

When trying out other commands i noticed that some the other command arguments had the \r in line endings pointed out by errors.

The issue was that the script had windows line endings, as steeldriver commented in the question.

It was en easy fix with the dos2unix command, ex:

dos2unix script.sh

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy