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

您所在的位置:网站首页 clion编译环境 Windows C/C++ CLion 开发环境搭建

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

2024-06-29 13:56:23| 来源: 网络整理| 查看: 265

博文目录

文章目录 IDE CLion安装设置MinGW如何在 UTF-8 编码下在控制台正常输出中文生成的 exe 运行时报错, 缺失 libgcc_s_seh-1.dll / libstdc++-6.dll生成的 exe 在没有 MinGW 环境的机器上如何正常运行在命令行 CMD 中运行 exe 时如何正常输出中文 插件测试 特殊配置 使用 CLion 开发 C++ CUDA 应用注意不要走如下弯路

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 startupOpen project in 选择 New WindowDefault 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 选 LeftClosing Policy - Tab limit 填 100 File | Settings | Editor | Font Font 选 Courier NewSize 填 16 File | Settings | Build, Execution, Deployment | Toolchains 添加编译器 MinGW, 有捆绑的用捆绑的, 否则自行下载配置 (点击 Environment 后面的 download) MinGW

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

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

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

解压到合适目录

在这里插入图片描述

如何在 UTF-8 编码下在控制台正常输出中文 参考 这里双击 Shift 键, 搜索 Registry 并打开, 取消 run.processes.with.pty 选项的勾选也可以在 main 最前面加 setbuf(stdout, NULL) 来关闭输出缓存, 避免因上面的修改导致的一些其他问题 生成的 exe 运行时报错, 缺失 libgcc_s_seh-1.dll / libstdc+±6.dll 将编译器 MinGW 的 bin 路径配置到 Path 环境变量, 这两个 dll 在该路径中 如果使用的是 CLion 自带的 MinGW, 则在 CLion 目录下找到 bin\mingw\bin 路径并配置到 Path 生成的 exe 在没有 MinGW 环境的机器上如何正常运行 将依赖的 dll 一同拷贝到 exe 目录下, 可以借助 dependencies 工具, 参考 这里尝试过在 CMakeLists.txt 中添加如下配置, 都不行 set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++")set(CMAKE_EXE_LINKER_FLAGS "-static")set(CMAKE_EXE_LINKER_FLAGS -static-libgcc -static-libstdc++)set(CMAKE_EXE_LINKER_FLAGS -static 在命令行 CMD 中运行 exe 时如何正常输出中文 暂时只能将 cpp 源文件编码转换成 GBK 并重新编译 插件 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]


【本文地址】

公司简介

联系我们

今日新闻


点击排行

实验室常用的仪器、试剂和
说到实验室常用到的东西,主要就分为仪器、试剂和耗
不用再找了,全球10大实验
01、赛默飞世尔科技(热电)Thermo Fisher Scientif
三代水柜的量产巅峰T-72坦
作者:寞寒最近,西边闹腾挺大,本来小寞以为忙完这
通风柜跟实验室通风系统有
说到通风柜跟实验室通风,不少人都纠结二者到底是不
集消毒杀菌、烘干收纳为一
厨房是家里细菌较多的地方,潮湿的环境、没有完全密
实验室设备之全钢实验台如
全钢实验台是实验室家具中较为重要的家具之一,很多

推荐新闻


图片新闻

实验室药品柜的特性有哪些
实验室药品柜是实验室家具的重要组成部分之一,主要
小学科学实验中有哪些教学
计算机 计算器 一般 打孔器 打气筒 仪器车 显微镜
实验室各种仪器原理动图讲
1.紫外分光光谱UV分析原理:吸收紫外光能量,引起分
高中化学常见仪器及实验装
1、可加热仪器:2、计量仪器:(1)仪器A的名称:量
微生物操作主要设备和器具
今天盘点一下微生物操作主要设备和器具,别嫌我啰嗦
浅谈通风柜使用基本常识
 众所周知,通风柜功能中最主要的就是排气功能。在

专题文章

    CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭