JetBrains C++ IDE CLion配置与评测

等了大半年的JetBrains C++ IDE千呼万唤始出来!上次我猜2014年肯定发布,今天经@wet2_cn同学的提醒,我去官博一看,嘿!有了!赶紧安装试了一把,感觉这是迄今为止用过最好的Cpp IDE,没有之一,这里做个简单的评测与推荐。

下载地址在这里,这是一款跨平台的IDE,简介参考《JetBrains C++ IDE 推荐》,这次仅仅谈些使用感受。

首先Windows用户需要安装MinGW,有GUI可以用,包不用下载很多,基本的几个就够用:

或者你也可以试试我准备的MinGW离线懒人包

接着安装CLion,在ToolChain配置界面指定MinGW的安装位置即可(下图是安装完毕后的配置图,并非欢迎界面的配置图,但是两者内容都是一样的):

接着新建一个HelloWord项目,写点C++11的新特性代码:

  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     cout << "Hello, World!" << endl;
  7.     auto name = "hankcs";
  8.     cout << name << endl;
  9.     return 0;
  10. }

编译运行,咦?出错了:

  1. HelloCLionmain.cpp: In function 'int main()':
  2. HelloCLionmain.cpp:7:10: error: 'name' does not name a type
  3.      auto name = "hankcs";
  4.           ^
  5. HelloCLionmain.cpp:8:13: error: 'name' was not declared in this scope
  6.      cout << name << endl;
  7.              ^
  8. CMakeFilesHelloCLion.diruild.make:53: recipe for target 'CMakeFiles/HelloCLion.dir/main.cpp.obj' failed
  9. mingw32-make.exe[3]: *** [CMakeFiles/HelloCLion.dir/main.cpp.obj] Error 1
  10. CMakeFilesMakefile2:59: recipe for target 'CMakeFiles/HelloCLion.dir/all' failed
  11. mingw32-make.exe[2]: *** [CMakeFiles/HelloCLion.dir/all] Error 2
  12. CMakeFilesMakefile2:71: recipe for target 'CMakeFiles/HelloCLion.dir/rule' failed
  13. mingw32-make.exe[1]: *** [CMakeFiles/HelloCLion.dir/rule] Error 2
  14. Makefile:105: recipe for target 'HelloCLion' failed
  15. mingw32-make.exe: *** [HelloCLion] Error 2

这是因为没有加C++11的编译参数,其实MinGW完全支持C++11,只需要在CMakeLists.txt中加一句:

  1. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++0x")

就行了:

  1. Hello, World!
  2. hankcs

整个编译链接运行的过程非常流畅,比VS爽多了。

MinGW还支持WindowsSDK,如果你习惯SDK而不是MFC的话,完全可以用这个替代VS。

  1. #include <iostream>
  2. #include "windows.h"
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     cout << "Hello, World!" << endl;
  9.     auto name = "hankcs";
  10.     cout << name << endl;
  11.     MessageBox(NULL, "hello", "caption", MB_OK);
  12.     return 0;
  13. }

不过CLion在我敲了auto之后没有智能提示我改编译选项,新建项目的时候也没有这些选项,感觉还是不太完善,后续版本可能会慢慢改进吧。

原文地址:https://www.cnblogs.com/huaxingtianxia/p/8261104.html