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

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

或者你也可以试试我准备的MinGW离线懒人包。
接着安装CLion,在ToolChain配置界面指定MinGW的安装位置即可(下图是安装完毕后的配置图,并非欢迎界面的配置图,但是两者内容都是一样的):

接着新建一个HelloWord项目,写点C++11的新特性代码:
|
1
2
3
4
5
6
7
8
9
10
|
#include <iostream>using namespace std;int main(){ cout << "Hello, World!" << endl; auto name = "hankcs"; cout << name << endl; return 0;} |
编译运行,咦?出错了:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
\HelloCLion\main.cpp: In function 'int main()':\HelloCLion\main.cpp:7:10: error: 'name' does not name a type auto name = "hankcs"; ^\HelloCLion\main.cpp:8:13: error: 'name' was not declared in this scope cout << name << endl; ^CMakeFiles\HelloCLion.dir\build.make:53: recipe for target 'CMakeFiles/HelloCLion.dir/main.cpp.obj' failedmingw32-make.exe[3]: *** [CMakeFiles/HelloCLion.dir/main.cpp.obj] Error 1CMakeFiles\Makefile2:59: recipe for target 'CMakeFiles/HelloCLion.dir/all' failedmingw32-make.exe[2]: *** [CMakeFiles/HelloCLion.dir/all] Error 2CMakeFiles\Makefile2:71: recipe for target 'CMakeFiles/HelloCLion.dir/rule' failedmingw32-make.exe[1]: *** [CMakeFiles/HelloCLion.dir/rule] Error 2Makefile:105: recipe for target 'HelloCLion' failedmingw32-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
2
|
Hello, World!hankcs |
整个编译链接运行的过程非常流畅,比VS爽多了。
MinGW还支持WindowsSDK,如果你习惯SDK而不是MFC的话,完全可以用这个替代VS。
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
#include <iostream>#include "windows.h"using namespace std;int main(){ cout << "Hello, World!" << endl; auto name = "hankcs"; cout << name << endl; MessageBox(NULL, "hello", "caption", MB_OK); return 0;} |

不过CLion在我敲了auto之后没有智能提示我改编译选项,新建项目的时候也没有这些选项,感觉还是不太完善,后续版本可能会慢慢改进吧。
转载请注明:码农场 » JetBrains C++ IDE CLion配置与评测

浙公网安备 33010602011771号