下载地址在这里,这是一款跨平台的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
|
HelloCLionmain.cpp: In function 'int main()': HelloCLionmain.cpp:7:10: error: 'name' does not name a type auto name = "hankcs"; ^ HelloCLionmain.cpp:8:13: error: 'name' was not declared in this scope cout << name << endl; ^ CMakeFilesHelloCLion.dirbuild.make:53: recipe for target 'CMakeFiles/HelloCLion.dir/main.cpp.obj' failed mingw32-make.exe[3]: *** [CMakeFiles/HelloCLion.dir/main.cpp.obj] Error 1 CMakeFilesMakefile2:59: recipe for target 'CMakeFiles/HelloCLion.dir/all' failed mingw32-make.exe[2]: *** [CMakeFiles/HelloCLion.dir/all] Error 2 CMakeFilesMakefile2:71: recipe for target 'CMakeFiles/HelloCLion.dir/rule' failed mingw32-make.exe[1]: *** [CMakeFiles/HelloCLion.dir/rule] Error 2 Makefile:105: recipe for target 'HelloCLion' failed 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
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配置与评测
原文链接: https://www.cnblogs.com/daleloogn/p/4727176.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/220549
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!