如何设置CLion进行编译和运行? [英] How do I set up CLion to compile and run?

查看:1847
本文介绍了如何设置CLion进行编译和运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚从


当我尝试运行该应用程序时,它指向我编辑配置,因此我添加了一个新应用程序,现在出现了这个问题:


  1. 我无法指定目标;我唯一能做的就是设置所有目标。

  2. 我无法指定配置。 (我发现的所有教程都在此处调试或运行)。

  3. 可执行吗?嗯通往GCC的道路应该在这里吗? (C:\MinGW\bin\gcc.exe)

其余配置似乎是可选的。


我的CMakeList.txt如下:

  cmake_minimum_required(版本3.3)
项目(测试)

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

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

我尝试使用所有目标来运行它。我也尝试设置可执行文件。我尝试了所有内容,但无法使其正常工作。


有人可以建议吗?

解决方案

在更新Windows 10之后,我遇到了与CLion 1.2.1相同的问题(在编写此答案时)。在更新操作系统之前,它工作正常。我的操作系统安装在C:\驱动器中,而CLion 1.2.1和Cygwin(64位)安装在D:\驱动器中。



问题似乎与CMake有关。我正在使用Cygwin。以下是简短的答案以及我用来解决该问题的步骤。



SHORT ANSWER (对于MinGW也应类似,但我没有尝试过)


  1. 安装 Cygwin,带有GCC,G ++,GDB和CMake(所需版本)

  2. 将Cygwin'bin'目录的完整路径添加到Windows 环境变量

  3. 重新启动CLion并选中'Settings'->' Build,Execution,Deployment以确保CLion选择了正确版本的Cygwin,make和gdb

  4. 检查项目配置(运行->编辑配置)以确保您的项目名称出现在此处,并且可以在目标,配置和可执行文件字段中选择选项。

  5. 构建,然后运行

  6. 享受

长答案:



以下是为我解决此问题的详细步骤:


  1. 安装l /删除以前版本的Cygwin(在您的情况下为MinGW)


  2. 确保CLion是最新的


  3. 运行Cygwin设置(我的64位操作系统为x64)


  4. 至少为Cygwin安装以下软件包:

    gcc
    g ++
    make
    Cmake
    gdb

    Make确保您安装了CLion所需的上述软件包的正确版本。您可以在CLion的快速入门部分找到所需的版本号(在拥有更多信誉点之前,我不能发布2个以上的链接)。


  5. 下一步,您需要将Cygwin(或MinGW)添加到名为 'Path' 的Windows环境变量中。您可以通过Google如何找到适用于您Windows版本的环境变量


[在Win 10上,右键单击此PC,然后选择属性->高级系统设置->环境变量...->在系统变量下->找到路径->单击编辑]


  1. 将'bin'文件夹添加到Path变量。对于Cygwin,我添加了:
    D:\cygwin64\bin


  2. 开始单击CLion并从欢迎屏幕或文件->设置


  3. <转至 设置 p>选择 构建,执行,部署 ,然后单击 工具链


  4. 您的环境 应该显示指向Cygwin安装目录(或MinGW)的正确路径


  5. 对于'CMake可执行文件',选择'使用捆绑的CMake xxx'(在撰写此答案时,本人为3.3.2)


  6. 'Debugger'告诉我'Cygwin GDB GNU gdb(GDB)7.8' [太该行中有很多gdb;-)]


  7. 下面,它应该为所有类别显示一个选中标记,还应该显示通往'的正确路径make''C编译器''C ++编译器'


查看屏幕截图:
检查编译器,make和gdb的所有路径


  1. 现在转到 '运行'->'编辑配置' 。您应该在左侧面板中看到您的项目名称,在右侧面板中看到配置。

查看截图:
检查配置以运行项目


  1. 在控制台窗口中应该没有错误。您将看到 'Run'->'Build' 选项现在处于活动状态


  2. Build您的项目,然后运行该项目。您应该在终端窗口中看到输出


希望这会有所帮助!祝您好运,并喜欢CLion。


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").

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?

解决方案

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

Hope this helps! Good luck and enjoy CLion.

这篇关于如何设置CLion进行编译和运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆