cmake gives current working directory cannot establish error

while executing cmake command it gives me the following error
“Current working directory cannot be established.”

I have executed cmake command from the shell script.
rm -rf build && mkdir -p build && cd build &&
cmake -DCMAKE_TOOLCHAIN_FILE=…/toolchain.cmake … 2>> output_file.txt && make clean && make 2>> output_file.txt && cd …

Let me know if you need more information.

Thanks,
Jalpan Parekh

Instead of doing all that it’s simpler to just use cmake like this:

rm -rf build
cmake -S . -B build …

That way you can get rid of you mkdir/cd logic

Also you don’t have to invoke make directly.

you can just cmake to build

cmake --build build --config Release

cmake command ilne:
https://cmake.org/cmake/help/latest/manual/cmake.1.html

Hi John Palmer,

Thanks for the support.

Below command works fine:

rm -rf build && cmake -DCMAKE_TOOLCHAIN_FILE=../toolchain.cmake -S . -B build && cmake --build build --config Release

Now how can I store error logs into one file? Can you please guide me?

Thanks,

Error logs? Which error logs are you looking for?

I am asking for capturing compile-time error logs in the file.
For example, if I use the “make” command to compile my code then the "make 2>> output_file.txt" command will store error logs in the output_file.txt file.

So how we can do the same with cmake --build command.

Thanks in advance.

2>> is not specific to make, you can use it with any command that outputs to stderr.
Thus cmake --build build --config Release 2>> output_file.txt should be close to what you want.

I hope this helps.

Thank you for the better understanding and it’s working now.