20

I'm using MacOS and trying to write c++ code in Clion but when I run the simple hello world code I get the error executable is not specified. I'm new to Clion.

Cmakelist.txt

cmake_minimum_required(VERSION 3.2)
project(untitled)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

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

clion

Dylan Corriveau
  • 2,561
  • 4
  • 29
  • 36
  • Since CLion is based on CMake, do you have an executable target in one of your CMakeLists.txt? If so, there should be an executable target you can run. This is of course me simply going off of memory from when CLion was still EAP. – Scott May 06 '15 at 19:53
  • i added content of makelist.txt. And what does `EAP` stand for ? @Scott –  May 06 '15 at 19:58
  • EAP simply means Early Access Program where you could use pre-released versions of CLion to try it out and report issues. Are there any other options in the Target dropdown other than "All targets"? It seems like you should have a target called untitled that would be an executable. – Scott May 06 '15 at 20:10
  • where the option All targets ? How can I find @Scott –  May 06 '15 at 20:16
  • I was referring to the "Target" dropdown in the screenshot you provided. Here is a link that provides more documentation about how to run and debug your code in CLion. https://www.jetbrains.com/clion/features/#run_and_debug – Scott May 06 '15 at 20:26
  • that's it! untitled target i selected thank you @Scott –  May 06 '15 at 21:17
  • Absolute fail. A "hello world" does not work. Sorry, there is no excuse. I know that there might an obvious fix those who are familiar with C tooling but I am a Java guy. – Alex Jan 31 '19 at 16:16

5 Answers5

7

If you have created C/C++ Library by mistake, make sure that you make a new project with C/C++ executable. Then you will be able to debug it out of the box.

screenshot

Vishal Singh
  • 1,341
  • 14
  • 13
5

I think CLion needs CMakeLists.txt for run/debug configuration. More info at: https://www.jetbrains.com/clion/help/cmakelists-file.html

As a C++ newbie, I have basically created new project in CLion then copy/past CMakeLists.txt content into my project by editing required fields.

After that, I was able to configure my project for run/debug.

Default CMakeLists.txt content should be something like this:

cmake_minimum_required(VERSION 3.3)
project(YourProjectName)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

set(SOURCE_FILES YourSourceFile.cpp)
add_executable(YourProjectName ${SOURCE_FILES})

I hope this helps.

gkc
  • 449
  • 6
  • 18
4

You just need choose target only for you application (choose your application name).

Like this enter image description here

whalemare
  • 1,107
  • 1
  • 13
  • 30
2

What I can tell from the original posts' image is that this build config is for a "c library" project type.

Solution: create a new project of type "c executable". When you launch this project, and hit run the application does run.

While this doesn't answer the question of whey the project type "c library" won't execute out of the box, it will get a newbie in business of tinkering with c.

I hope this helps.

Thirdshift
  • 71
  • 4
-1

image of what to click

click the left button “+” select “generate the coffee”

alistaire
  • 42,459
  • 4
  • 77
  • 117
Snail
  • 3,046
  • 1
  • 9
  • 12