mirror of
https://github.com/Dichgrem/Blog.git
synced 2025-07-30 16:49:31 -04:00
241 lines
9.1 KiB
HTML
241 lines
9.1 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="en">
|
||
|
||
<head>
|
||
<title>Dich'blog</title>
|
||
|
||
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1">
|
||
<meta name="robots" content="noodp"/>
|
||
|
||
<link rel="stylesheet" href="https://blog.dich.bid/style.css">
|
||
<link rel="stylesheet" href="https://blog.dich.bid/color/blue.css">
|
||
|
||
<link rel="stylesheet" href="https://blog.dich.bid/color/background_dark.css">
|
||
|
||
<link rel="stylesheet" href="https://blog.dich.bid/font-hack-subset.css">
|
||
|
||
<meta name="description" content="">
|
||
|
||
<meta property="og:description" content="">
|
||
<meta property="og:title" content="Dich'blog">
|
||
<meta property="og:type" content="article">
|
||
<meta property="og:url" content="https://blog.dich.bid/windows-6-c/">
|
||
|
||
<meta name="twitter:card" content="summary_large_image">
|
||
<meta name="twitter:description" content="">
|
||
<meta name="twitter:title" content="Dich'blog">
|
||
<meta property="twitter:domain" content="blog.dich.bid">
|
||
<meta property="twitter:url" content="https://blog.dich.bid/windows-6-c/">
|
||
|
||
<link rel="alternate" type="application/atom+xml" title="Dich'blog Atom Feed" href="https://blog.dich.bid/atom.xml" />
|
||
|
||
|
||
<link rel="icon" type="image/png" href=/dich.webp />
|
||
|
||
<!-- ✅ Added center alignment styles -->
|
||
<style>
|
||
.footer {
|
||
text-align: center;
|
||
padding: 1rem 0;
|
||
}
|
||
|
||
.footer__inner {
|
||
display: flex;
|
||
justify-content: center;
|
||
flex-direction: column;
|
||
align-items: center;
|
||
}
|
||
|
||
.copyright {
|
||
text-align: center;
|
||
}
|
||
</style>
|
||
</head>
|
||
|
||
<body class="">
|
||
<div class="container">
|
||
|
||
<header class="header">
|
||
<div class="header__inner">
|
||
<div class="header__logo">
|
||
|
||
<a href="https://blog.dich.bid" style="text-decoration: none;">
|
||
<div class="logo">
|
||
|
||
Dich'blog
|
||
|
||
</div>
|
||
</a>
|
||
</div>
|
||
</div>
|
||
|
||
|
||
|
||
<nav class="menu">
|
||
<ul class="menu__inner">
|
||
<li class="active"><a href="https://blog.dich.bid">blog</a></li>
|
||
|
||
<li><a href="https://blog.dich.bid/archive">archive</a></li>
|
||
|
||
<li><a href="https://blog.dich.bid/tags">tags</a></li>
|
||
|
||
<li><a href="https://blog.dich.bid/weekly">weekly</a></li>
|
||
|
||
<li><a href="https://blog.dich.bid/search">search</a></li>
|
||
|
||
<li><a href="https://blog.dich.bid/about">about me</a></li>
|
||
|
||
<li><a href="https://blog.dich.bid/links">links</a></li>
|
||
|
||
<li><a href="https://blog.dich.bid/atom.xml">rss</a></li>
|
||
|
||
<li><a href="https://github.com/Dichgrem" target="_blank" rel="noopener noreferrer">github</a></li>
|
||
</ul>
|
||
</nav>
|
||
|
||
|
||
|
||
</header>
|
||
|
||
|
||
<div class="content">
|
||
|
||
<div class="post">
|
||
|
||
<h1 class="post-title"><a href="https://blog.dich.bid/windows-6-c/">Windows系列(6):C/C++开发配置</a></h1>
|
||
<div class="post-meta-inline">
|
||
|
||
<span class="post-date">
|
||
2024-05-30
|
||
</span>
|
||
|
||
</div>
|
||
|
||
|
||
<span class="post-tags-inline">
|
||
:: tags:
|
||
<a class="post-tag" href="https://blog.dich.bid/tags/windows/">#Windows</a></span>
|
||
|
||
|
||
<div class="post-content">
|
||
<p>前言 由于 Windows 中开发环境较 linux 复杂,这里总结 Windows 中使用 VScode 开发 C/C++ 的环境配置。</p>
|
||
<span id="continue-reading"></span><h2 id="bu-zou">步骤</h2>
|
||
<ul>
|
||
<li>下载安装 Vscode(Visual Studio Code)</li>
|
||
<li>配置安装中文插件,C/C++插件和 Code Runner 插件</li>
|
||
<li>安装 MinGW64 编译器并配置环境变量</li>
|
||
<li>配置 tasks.json 和 launch.json</li>
|
||
<li>开始C/C++之旅!</li>
|
||
</ul>
|
||
<h2 id="an-zhuang-vscode">安装VScode</h2>
|
||
<ul>
|
||
<li><a href="https://code.visualstudio.com/">官网</a>-微软官方版</li>
|
||
<li><a href="https://github.com/VSCodium/vscodium">vscodium</a>-社区开源版本,去除官方版中不开源成分</li>
|
||
</ul>
|
||
<h2 id="pei-zhi-cha-jian">配置插件</h2>
|
||
<ul>
|
||
<li>默认为英文,在左侧 <code>Extensions</code> 中安装 <code>Chinese(simplified)</code> 插件,重启即可变为中文;</li>
|
||
<li>随后安装<a href="https://github.com/Microsoft/vscode-cpptools">C/C++插件</a>,即下载名称为<code>cpptools-windows-x64.vsix</code>
|
||
的插件并在扩展中<code>从VSIX安装</code>,然后搜索 Code Runner 并安装。</li>
|
||
</ul>
|
||
<h2 id="an-zhuang-mingw64-bian-yi-qi">安装 MinGW64 编译器</h2>
|
||
<ul>
|
||
<li>
|
||
<p>首先打开<a href="https://www.mingw-w64.org/">官方文档</a>,然后点击左侧的 Downloads,再点击 Pre-built Toolchains。往下拉,可以看到许多系统的下载包,这里我们选<code>MinGW-W64-builds</code>并点击。页面自动跳转,再点击最上方的 MinGW-W64-builds 下的 GitHub 链接。</p>
|
||
</li>
|
||
<li>
|
||
<p>进入Github,找到<code>x86_64-14.2.0-release-win32-seh-ucrt-rt_v12-rev1.7z</code>(版本会更新,选择最新的即可)点击然后下载。</p>
|
||
</li>
|
||
<li>
|
||
<p>下载完成后解压得到 mingw64 文件夹,将其移动到<code>C:\Program Files</code>下,随后复制该文件夹中/bin的路径。</p>
|
||
</li>
|
||
<li>
|
||
<p>按下 Win + S,在搜索框中输入“系统环境变量”,点击“编辑系统环境变量“,点击环境变量。在下方的系统变量中,选中<code>Path</code>,然后点击编辑,点击右侧的新建,然后黏贴刚刚拷贝的路径,随后一直用<code>确定</code>退出。</p>
|
||
</li>
|
||
<li>
|
||
<p>检验是否成功:在cmd中输入<code>gcc -v</code>,如果有版本号则成功。</p>
|
||
</li>
|
||
</ul>
|
||
<h2 id="pei-zhi-json">配置JSON</h2>
|
||
<ul>
|
||
<li>回到 Visual Studio Code 继续配置。点击左侧的资源管理器,点击打开文件夹,创建一个<code>.cpp</code>文件,里面代码可以是</li>
|
||
</ul>
|
||
<pre style="background-color:#151515;color:#e8e8d3;"><code><span>#include <iostream>
|
||
</span><span>
|
||
</span><span>int main() {
|
||
</span><span> std::cout << "Hello" << std::endl;
|
||
</span><span> return 0;
|
||
</span><span>}
|
||
</span></code></pre>
|
||
<ul>
|
||
<li>
|
||
<p>保存,然后点击右上角的三角形,选择“运行C/C++文件”。此时上方的搜索框会有弹出,点击“C/C++: g++.exe 构建和调试活动文件”。 然后会生成一个 .vscode 的文件夹,里面包含 tasks.json 文件。打开这个文件,然后按需调整,设置栈空间(这里设置成了256MB)和 C++ 标准(这里设置成C++17)。</p>
|
||
</li>
|
||
<li>
|
||
<p>接着生成调试文件,用于进行 debug。点击左侧的运行和调试,然后点击“创建 launch.json 文件”。点击弹出的“另外 C++ (GDB/LLDB) 个选项”。</p>
|
||
</li>
|
||
<li>
|
||
<p>点击右下角的“添加配置”,然后点击“C/C++: (gbd) 启动”。对Program部分进行修改(编译产物的路径)。</p>
|
||
</li>
|
||
</ul>
|
||
<blockquote>
|
||
<p>手动编译:<code>g++ <源代码的相对路径></code> 手动运行编译产物:一般为<code>./a.out</code></p>
|
||
</blockquote>
|
||
<p>至此 Visual Studio Code 的 C++ 环境已经配置完成。</p>
|
||
<blockquote>
|
||
<p>在ubuntu上配置环境需要安装 <code>sudo apt install build-essential gdb cmake clangd clang-format libstdc++-dev</code></p>
|
||
</blockquote>
|
||
<hr />
|
||
<p><strong>Done.</strong></p>
|
||
|
||
</div>
|
||
|
||
|
||
<div class="pagination">
|
||
<div class="pagination__title">
|
||
<span class="pagination__title-h">Thanks for reading! Read other posts?</span>
|
||
<hr />
|
||
</div>
|
||
<div class="pagination__buttons">
|
||
<span class="button previous">
|
||
<a href="https://blog.dich.bid/windows-4-auto/">
|
||
<span class="button__icon">←</span>
|
||
<span class="button__text">Windows系列(4):封装与全自动安装</span>
|
||
</a>
|
||
</span>
|
||
|
||
|
||
<span class="button next">
|
||
<a href="https://blog.dich.bid/windows-5-py/">
|
||
<span class="button__text">Windows系列(5):Python开发配置</span>
|
||
<span class="button__icon">→</span>
|
||
</a>
|
||
</span>
|
||
</div>
|
||
</div>
|
||
|
||
</div>
|
||
|
||
</div>
|
||
|
||
|
||
<footer class="footer">
|
||
<div class="footer__inner">
|
||
<div class="copyright">
|
||
<span>©
|
||
2025
|
||
Dichgrem</span>
|
||
<span class="copyright-theme">
|
||
<span class="copyright-theme-sep"> :: CC BY-SA 4.0 :: A friend comes from distant lands</span>
|
||
</a>
|
||
</span>
|
||
</div>
|
||
</div>
|
||
</footer>
|
||
|
||
</div>
|
||
</body>
|
||
</html>
|
||
|