How do I set up CLion to compile and run?
Asked Answered
R

3

67

I just downloaded CLion from https://www.jetbrains.com/ because I just love the rest of their products.

However, I'm having problems configuring it. I'm not able to compile and run my application (a simple "hello world").

Screenshot

When I try to run the application, it refers me to "Edit configuration", so I added a new application and now I have this problem:

  1. I cannot specify the "target"; the only thing I can do is set "All targets".
  2. I cannot specify the "configuration" (all tutorials I found have Debug or Run here).
  3. Executable? Hmm. Should the path to GCC be here? (C:\MinGW\bin\gcc.exe)

The rest of the configuration looks optional.

My CMakeList.txt looks like:

cmake_minimum_required(VERSION 3.3)
project(test)

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

set(SOURCE_FILES test.c test.h)
add_executable(test ${SOURCE_FILES})

I tried to run this with "All targets". I also tried to set the executable. I tried everything, but I'm not able to make it work.

Can anyone advise?

Rifkin answered 21/10, 2015 at 19:7 Comment(1)
for Ubuntu: sudo apt-get install cmakeBannerol
G
97

I ran into the same issue with CLion 1.2.1 (at the time of writing this answer) after updating Windows 10. It was working fine before I had updated my OS. My OS is installed in C:\ drive and CLion 1.2.1 and Cygwin (64-bit) are installed in D:\ drive.

The issue seems to be with CMake. I am using Cygwin. Below is the short answer with steps I used to fix the issue.

SHORT ANSWER (should be similar for MinGW too but I haven't tried it):

  1. Install Cygwin with GCC, G++, GDB and CMake (the required versions)
  2. Add full path to Cygwin 'bin' directory to Windows Environment variables
  3. Restart CLion and check 'Settings' -> 'Build, Execution, Deployment' to make sure CLion has picked up the right versions of Cygwin, make and gdb
  4. Check the project configuration ('Run' -> 'Edit configuration') to make sure your project name appears there and you can select options in 'Target', 'Configuration' and 'Executable' fields.
  5. Build and then Run
  6. Enjoy

LONG ANSWER:

Below are the detailed steps that solved this issue for me:

  1. Uninstall/delete the previous version of Cygwin (MinGW in your case)

  2. Make sure that CLion is up-to-date

  3. Run Cygwin setup (x64 for my 64-bit OS)

  4. Install at least the following packages for Cygwin: gcc g++ make Cmake gdb Make sure you are installing the correct versions of the above packages that CLion requires. You can find the required version numbers at CLion's Quick Start section (I cannot post more than 2 links until I have more reputation points).

  5. Next, you need to add Cygwin (or MinGW) to your Windows Environment Variable called 'Path'. You can Google how to find environment variables for your version of Windows

[On Win 10, right-click on 'This PC' and select Properties -> Advanced system settings -> Environment variables... -> under 'System Variables' -> find 'Path' -> click 'Edit']

  1. Add the 'bin' folder to the Path variable. For Cygwin, I added: D:\cygwin64\bin

  2. Start CLion and go to 'Settings' either from the 'Welcome Screen' or from File -> Settings

  3. Select 'Build, Execution, Deployment' and then click on 'Toolchains'

  4. Your 'Environment' should show the correct path to your Cygwin installation directory (or MinGW)

  5. For 'CMake executable', select 'Use bundled CMake x.x.x' (3.3.2 in my case at the time of writing this answer)

  6. 'Debugger' shown to me says 'Cygwin GDB GNU gdb (GDB) 7.8' [too many gdb's in that line ;-)]

  7. Below that it should show a checkmark for all the categories and should also show the correct path to 'make', 'C compiler' and 'C++ compiler'

See screenshot: Check all paths to the compiler, make and gdb

  1. Now go to 'Run' -> 'Edit configuration'. You should see your project name in the left-side panel and the configurations on the right side

See screenshot: Check the configuration to run the project

  1. There should be no errors in the console window. You will see that the 'Run' -> 'Build' option is now active

  2. Build your project and then run the project. You should see the output in the terminal window

Generate answered 14/11, 2015 at 10:43 Comment(4)
Thanks for this! I had gone through this twice before on my own, but was missing the setting of the environment variable. Now all is right in the world!Zollverein
How do you install a particular version of CMake using Cygwin? It does not give you an option, it seems. I get a choice between "keep", "skip", and whatever version is there. Thanks.Excurvature
@user3195297: I am not sure how. But I know it is possible. I know that CMake is backwards compatible. So you can install the latest one too and it should be fine. Regarding installing a specific older package, please look at this thread. I hope it helps. I apologize that I have not done this and hopefully someone else will be able to help you. With Google's help, I am sure you will find some possible answers: #461244Generate
As of 13/12/2021, some mirrors (or atleast the first one) literally do not have gcc, g++, and make. Don't go through the same torture I did if you can't find them in package selection. Just close the cygwin installer, select a different mirror and you should find them.Drandell
U
6

I met some problems in Clion and finally, I solved them. Here is some experience.

  1. Download and install MinGW
  2. g++ and gcc package should be installed by default. Use the MinGW installation manager to install mingw32-libz and mingw32-make. You can open MinGW installation manager through C:\MinGW\libexec\mingw-get.exe This step is the most important step. If Clion cannot find make, C compiler and C++ compiler, recheck the MinGW installation manager to make every necessary package is installed.
  3. In Clion, open File->Settings->Build,Execution,Deployment->Toolchains. Set MinGW home as your local MinGW file.
  4. Start your "Hello World"!
Undergird answered 30/6, 2017 at 22:23 Comment(1)
I tried Cygwin but failed. Then I tried MinGW, it succeeded smoothly after I followed the official manual.Swabber
S
1

You can also use Microsoft Visual Studio compiler instead of Cygwin or MinGW in Windows environment as the compiler for CLion.

Just go to find Actions in Help and type "Registry" without " and enable CLion.enable.msvc Now configure toolchain with Microsoft Visual Studio Compiler. (You need to download it if not already downloaded)

follow this link for more details: https://www.jetbrains.com/help/clion/quick-tutorial-on-configuring-clion-on-windows.html

Selma answered 27/3, 2018 at 7:27 Comment(1)
I do not have "CLion.enable.msvc", then what to do? Thanks!Cowrie

© 2022 - 2024 — McMap. All rights reserved.