Windows C/C++ CLion 开发环境搭建

博文目录


IDE CLion

安装

官网
官方全版本下载

CLion-2021.2.3.exe 或 CLion-2021.2.3.win.zip, 从 2021.3 起, IDE Eval Reset 不再可用, 复制评估 key 的方式从 2021.2.3 起不再可用

设置

  • File | Settings | Appearance & Behavior | System Settings - Project
    • 取消勾选 Reopen projects on startup
    • Open project in 选择 New Window
    • Default project directory 选择为 CLion 分配的工作空间目录, 如 C:\mrathena\develop\workspace\clion
  • File | Settings | Editor | General | Code Completion
    • 取消勾选 Match case
  • File | Settings | Editor | General | Editor Tabs
    • Appearance - Tab placement 选 Left
    • Closing Policy - Tab limit 填 100
  • File | Settings | Editor | Font
    • Font 选 Courier New
    • Size 填 16
  • File | Settings | Build, Execution, Deployment | Toolchains
    • 添加编译器 MinGW, 有捆绑的用捆绑的, 否则自行下载配置 (点击 Environment 后面的 download)

MinGW

MinGW与Clion下载安装及使用详解

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在 SourceForge 的跳转页, 往下翻, 直到 MinGW-W64 Online Installer

  • win32: Windows
  • posix: Linux / Unix / Mac OS 等
  • seh: 新的, 性能好的, 不支持 32 位. 64 位系统选 seh
  • sjlj: 旧的, 稳定性好, 支持 32 位

解压到合适目录

在这里插入图片描述

插件

  • Manage Plugin Repositories 添加知了插件源 plugins.zhile.io
    • 安装 IDE Eval Reset 插件, 记得勾选 Logout when reset 和 Auto reset before per restart, 注意, 2021.3 起不再可用
  • Chinese (Simplified) Language Pack / 中文语言包
  • Translation, 划词翻译
  • CodeGlance2, 代码地图
  • InLineError, 行内报错提示

测试

在这里插入图片描述

特殊配置 使用 CLion 开发 C++ CUDA 应用

Set up the CUDA compiler

On Windows, CUDA projects can be developed only with the Microsoft Visual C++ toolchain. Check the toolchain settings to make sure that the selected architecture matches with the architecture of the installed CUDA toolkit (usually, amd64).

Microsoft Visual C++

  • Install Visual Studio 2013, 2015, 2017, or 2019 on your system.
  • In CLion, go to File | Settings | Build, Execution, Deployment | Toolchains.
  • Click Icons general add and select Visual Studio from the list of toolchain templates.
  • Check the Environment field. CLion will attempt to automatically detect the installed Visual Studio distribution. If the detection fails, set the path to Visual Studio manually.
  • If required, specify the Architecture (x86, amd64, x86_arm, or another), Platform (store, uwp, onecore, or leave it blank), and Version. To build your project for the selected architecture, CLion will call the script to configure the environment with the specified parameters.
    • If the version of your compiler toolset is earlier than the version of your Visual Studio installation, pass it in the Version field via the vcvars_ver flag, for example, -vcvars_ver=14.16.
  • Wait until the tools detection is finished
    在这里插入图片描述

CLion 开发 CUDA 应用, 工具链必须使用 Visual Studio. 安装 Visual Studio 时必须选择 C++ 桌面开发里的 MSVC 和 Windows SDK

我的 CLion 是 2021.2.3, 最高支持 VS 2019, 所以我下载并安装了 VS 2019 社区版

Visual Studio 较旧的下载 - 2019、2017、2015 和以前的版本
Visual Studio Installer 2019.exe

CLion配置visual studio(msvc)和JOM多核编译

在这里插入图片描述
在这里插入图片描述

在 Toolchains 里创建 Visual Studio 并设置成默认(点到第一个), 确保默认的测试编译能成功通过(无法通过的例子见下面弯路说明)

在这里插入图片描述

CMake 里要确认 Toolchains 与当前使用的 Toolchains 对应

注意不要走如下弯路

先说结论, MSVC 和 Windows SDK 都得安装

我根据经验, 觉得配置 Visual Studio 工具链应该只需要用到 MSVC 编译器, 所以最开始就只安装了 MSVC. 结果在配置 Visual Studio 工具链的时候, 怎么都无法通过测试验证. 同时使用该工具链的任何工程做 Reload CMake Project 操作都会报相同的错. 因为输出信息乱码而不知道具体内容, 尝试百度错误代码也没百出来, 无奈只能先解决乱码问题

在这里插入图片描述

C:\mrathena\develop\clion-2021.2.3\bin\cmake\win\bin\cmake.exe -DCMAKE_BUILD_TYPE=Debug -DCMAKE_DEPENDS_USE_COMPILER=FALSE -G "CodeBlocks - NMake Makefiles" C:\mrathena\develop\workspace\clion\test
-- The C compiler identification is MSVC 19.29.30146.0
-- The CXX compiler identification is MSVC 19.29.30146.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: C:/mrathena/develop/visual.studio-2019/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe
-- Check for working C compiler: C:/mrathena/develop/visual.studio-2019/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - broken
CMake Error at C:/mrathena/develop/clion-2021.2.3/bin/cmake/win/share/cmake-3.20/Modules/CMakeTestCCompiler.cmake:66 (message):
  The C compiler

    "C:/mrathena/develop/visual.studio-2019/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: C:/mrathena/develop/workspace/clion/test/cmake-build-debug/CMakeFiles/CMakeTmp
    
    Run Build Command(s):nmake -f Makefile /nologo cmTC_0a29f\fast && 	C:\mrathena\develop\visual.studio-2019\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\nmake.exe  -f CMakeFiles\cmTC_0a29f.dir\build.make /nologo -L                  CMakeFiles\cmTC_0a29f.dir\build
    Building C object CMakeFiles/cmTC_0a29f.dir/testCCompiler.c.obj
    	C:\mrathena\develop\clion-2021.2.3\bin\cmake\win\bin\cmake.exe -E cmake_cl_compile_depends --dep-file=CMakeFiles\cmTC_0a29f.dir\testCCompiler.c.obj.d --working-dir=C:\mrathena\develop\workspace\clion\test\cmake-build-debug\CMakeFiles\CMakeTmp --filter-prefix="" -- C:\mrathena\develop\visual.studio-2019\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64\cl.exe @C:\Users\mrathena\AppData\Local\Temp\nmDFDE.tmp
    Linking C executable cmTC_0a29f.exe
    	C:\mrathena\develop\clion-2021.2.3\bin\cmake\win\bin\cmake.exe -E vs_link_exe --intdir=CMakeFiles\cmTC_0a29f.dir --rc=rc --mt=CMAKE_MT-NOTFOUND --manifests -- C:\mrathena\develop\visual.studio-2019\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64\link.exe /nologo @CMakeFiles\cmTC_0a29f.dir\objects1.rsp @C:\Users\mrathena\AppData\Local\Temp\nmE07B.tmp
    RC Pass 1: command "rc /fo CMakeFiles\cmTC_0a29f.dir/manifest.res CMakeFiles\cmTC_0a29f.dir/manifest.rc" failed (exit code 0) with the following output:
    绯荤粺鎵句笉鍒版寚瀹氱殑鏂囦欢銆侼MAKE : fatal error U1077: 鈥淐:\mrathena\develop\clion-2021.2.3\bin\cmake\win\bin\cmake.exe鈥�: 杩斿洖浠g爜鈥�0xffffffff鈥�
    Stop.
    NMAKE : fatal error U1077: 鈥淐:\mrathena\develop\visual.studio-2019\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\nmake.exe鈥�: 杩斿洖浠g爜鈥�0x2鈥�
    Stop.
    
    

  

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:2 (project)


-- Configuring incomplete, errors occurred!
See also "C:/mrathena/develop/workspace/clion/test/cmake-build-debug/CMakeFiles/CMakeOutput.log".
See also "C:/mrathena/develop/workspace/clion/test/cmake-build-debug/CMakeFiles/CMakeError.log".

[Finished]

Clion编译输出乱码问题解决方案

乱码问题可通过在 Help | Edit Custom VM Optisions… (不存在则点击 Create) 末尾添加如下两个参数解决. 添加后重启 CLion

-Dconsole.encoding=UTF-8
-Dfile.encoding=UTF-8

在这里插入图片描述

根据描述找到一篇 文章 解决了这个问题, 在 CMake 里配置参数 -G "Visual Studio 16 2019". 有用, 但是又出了一个新的报错. 这次输出内容里涉及到 Windwos SDK, 让我联想到 VS Install 里面的可选安装 Windows 10 SDK, 同时我也想起来看到过有 文章 里就只安装 MSVC 和 Windows SDK. 试了一下同时安装这两项内容. 试了一下, 两项都装果真就直接成了

C:\mrathena\develop\clion-2021.2.3\bin\cmake\win\bin\cmake.exe -G "Visual Studio 16 2019" C:\mrathena\develop\workspace\clion\test
-- Selecting Windows SDK version  to target Windows 10.0.22621.
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:2 (project):
  No CMAKE_C_COMPILER could be found.



CMake Error at CMakeLists.txt:2 (project):
  No CMAKE_CXX_COMPILER could be found.



-- Configuring incomplete, errors occurred!
See also "C:/mrathena/develop/workspace/clion/test/cmake-build-debug/CMakeFiles/CMakeOutput.log".
See also "C:/mrathena/develop/workspace/clion/test/cmake-build-debug/CMakeFiles/CMakeError.log".

[Finished]

猜你喜欢

转载自blog.csdn.net/mrathena/article/details/127480742