Why output saved in cmake-build-debug

Answered

I have a C++ project and whenever I save something it gets saved in cmake-build-debug , which is a folder created automatically when building the CMakeLists.txt in CLion.

  • Why it does not get saved in my current executing folder?

My project looks like:

Camera Motion
-- cmake-build-debug
---- ...
-- CMakeLists.txt
-- calibration.cpp


# CMakeLists.txt
cmake_minimum_required(VERSION 3.15)
project(CameraMotion)

set(CMAKE_CXX_STANDARD 14)

find_package( OpenCV REQUIRED )
include_directories(${OpenCV_INCLUDE_DIRS})

add_executable(CameraMotion calibration.cpp)
target_link_libraries(CameraMotion ${OpenCV_LIBS})


// calibration.cpp
#include <iostream>

int main()
{
std::ofstream myfile;
myfile.open("output.txt");
myfile << "output\n";
myfile.close();
}

When I run the project in CLion it says:

====================[ Build | CameraMotion | Debug ]============================
/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake --build /Users/hectoresteban/CLionProjects/CameraMotion/cmake-build-debug --target CameraMotion -- -j 4
[100%] Built target CameraMotion

0
3 comments

Hello!

It's the location of build results. The default folders are cmake-build-debug for Debug profiles and cmake-build-release for Release profiles. You can always set  other locations of your choice in the Generation path field of your CMake profile (Settings / Preferences | Build, Execution, Deployment | CMake).

0

Understood but my first problem came that I wanted to import some images from a folder in the main directory, where CMakeText is but it constantly said that the folder I was trying to open did not exist. Then I saved one dummy file without specifying address to know which is the adress considered by CLion and it was cmake-build-debug . That said, my real problem is that I cannot read any file if this one is not inside cmake-build-debug. How can I configure the project to consider the path wehre the CMakeText file is as the default path when reading data?

0

It's a default C++ behavior -  if you use just a file name (without a full path), the file should be in the same folder as the executable. In your case it's cmake-build-debug.

If you want to open a file located in another folder, you need to use a full path.

0

Please sign in to leave a comment.