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

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

问题描述

我刚刚从

当我尝试运行应用程序时,它指向我编辑配置",所以我添加了一个新应用程序,现在我遇到了这个问题:

  1. 我无法指定目标";我唯一能做的就是设置所有目标".
  2. 我无法指定配置"(我发现的所有教程都在此处进行调试或运行).
  3. 可执行?唔.GCC的路径应该在这里吗?(C:MinGWingcc.exe)

其余的配置看起来是可选的.

我的 CMakeList.txt 看起来像:

cmake_minimum_required(VERSION 3.3)项目(测试)设置(CMAKE_CXX_FLAGS${CMAKE_CXX_FLAGS} -std=c++11")设置(SOURCE_FILES test.c test.h)添加可执行文件(测试 ${SOURCE_FILES})

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

谁能给点建议?

解决方案

我在更新 Windows 10 后遇到了与 CLion 1.2.1 相同的问题(在撰写此答案时).在我更新之前它运行良好我的操作系统.我的操作系统安装在 C: 驱动器中,CLion 1.2.1 和 Cygwin(64 位)安装在 D: 驱动器中.

问题似乎出在 CMake 上.我正在使用 Cygwin.以下是我用来解决问题的步骤的简短回答.

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

  1. 安装带有 GCC、G++、GDB 和 CMake(所需版本)的 Cygwin
  2. 将 Cygwin 'bin' 目录的完整路径添加到 Windows 环境变量
  3. 重新启动 CLion 并检查设置"->构建、执行、部署"以确保 CLion 已选择正确版本的 Cygwin、make 和 gdb
  4. 检查项目配置(运行"->编辑配置")以确保您的项目名称出现在那里,您可以在目标"、配置"和可执行"中选择选项字段.
  5. 构建然后运行
  6. 享受

长答案:

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

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

  2. 确保 CLion 是最新的

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

  4. 至少为 Cygwin 安装以下软件包:<代码>海湾合作委员会加++制作制作数据库确保您正在安装 CLion 所需的上述软件包的正确版本.您可以在 CLion 的快速入门"部分找到所需的版本号(在获得更多声誉点之前,我不能发布超过 2 个链接).

  5. 接下来,您需要将 Cygwin(或 MinGW)添加到名为 'Path' 的 Windows 环境变量中.您可以谷歌如何为您的 Windows 版本查找环境变量

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

  1. 将bin"文件夹添加到 Path 变量中.对于 Cygwin,我补充说:D:cygwin64in

  2. 启动 CLion 并从欢迎屏幕"或从文件"->设置"

  3. 转到设置"
  4. 选择'构建、执行、部署',然后点击'工具链'

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

  6. 对于'CMake executable',选择'Use bundled CMake xxx'(在我写这个答案的时候是3.3.2)

  7. 'Debugger' 显示给我看 'Cygwin GDB GNU gdb (GDB) 7.8' [该行中有太多 gdb ;-)]p>

  8. 下面应该显示所有类别的复选标记,还应该显示'make''C编译器''C++ 编译器'

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

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

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

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

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

希望这有帮助!祝你好运,享受 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:MinGWingcc.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:cygwin64in

  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天全站免登陆