56

I install the CLion on a Ubuntu 14.04. I build my first project with help CMakeLists.txt:

Source file:

#include <iostream>
using namespace std;

int main() {
  cout << "Hello, World!" << endl;
  return 0;
}

CMakeLists.txt:

cmake_minimum_required(VERSION 2.8.4)
project(sh)

set(SOURCE_FILES main.cpp)
add_executable(sh ${SOURCE_FILES})

My source file is located in a /home/user/Desktop/sh. But after build, I don't see any executable file in this folder. Where is it?

Dabbler
  • 9,733
  • 5
  • 41
  • 64
Denis
  • 3,595
  • 12
  • 52
  • 86

2 Answers2

83

When you build under CLion,

enter image description here

It prints the path it sends the executable to the Console:

-- Build files have been written to: /home/<user>/.clion10/system/cmake/generated/8bd932b1/8bd932b1/Debug1

To change this File > Settings..., and under CMake settings, enter the desired subdirectory name (e.g., 'bin') in the Working directory field:

enter image description here

(You may require Run > Clean before the new output path is used.)

Brent Faust
  • 9,103
  • 6
  • 53
  • 57
  • 1
    Thanks! Could you specify if this is a global setting for all Projects or is this somehow project specific? Also, is their potentially a variable name (e.g. "$PROJECT_NAME") that could be used in this "Build output path" setting? Otherwise, will all projects be build into the same directory (if I choose an absolute path)? – Chris Apr 16 '15 at 10:06
  • 1
    This works for me while the OP accepted answer does not work! – wdg May 22 '15 at 09:57
  • @wdg, It was about 8 months ago :) In past, that method worked good. – Denis May 27 '15 at 19:13
  • seems this setting affects the location of the executable only, e.g. one of the targets in my project is ctest executable, and I expect that cmake/ctest supporting files will be nearby to executable for the running, however it's not so. by the way, looks like this setting can't be defined by one of CMAKE variables, that would be useful – amigo421 May 12 '16 at 14:50
50

When you run the program, it shows the location at the top of the Run window:

/home/me/.clion10/system/cmake/generated/ad2f5c60/ad2f5c60/Debug/HelloCLion
Hello, World!

Process finished with exit code 0

You can modify this location by changing CMAKE_RUNTIME_OUTPUT_DIRECTORY:

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "/home/me/ClionProjects/Binaries")
sfjac
  • 7,119
  • 5
  • 45
  • 69
  • 2
    Not working for clion-138.1965.18. It is hardcoded; igonring the CMAKE_RUNTIME_OUTPUT_DIRECTORY ./home/js/Apps/clion-138.1965.18/bin/cmake/bin/cmake-x64 --build /home/js/.clion10/system/cmake/generated/37068b0b/37068b0b/Debug --target SomeProject -- -j 4 – Sridher Sep 20 '14 at 19:23
  • 2
    Works for me for clion-138.1965.18. Beware though that you have to **delete and re-create** the *Run configuration* for it to pick the change. – José Tomás Tocino Sep 29 '14 at 17:57
  • Added bonus that it is far more portable than relying on the IDE to take this step and is more inline with a real cmake build. – Mike McMahon May 12 '16 at 08:11
  • 2
    note that if you are building a library, you have to use the variable CMAKE_ARCHIVE_OUTPUT_DIRECTORY, or CMAKE_LIBRARY_OUTPUT_DIRECTORY instead – J-Mik Jun 04 '16 at 01:51
  • See http://stackoverflow.com/a/27547566/5025060 for a more flexible answer. – CODE-REaD Sep 28 '16 at 17:11