win10 安装 Cygwin

2023-11-10

http://preshing.com/20141108/how-to-install-the-latest-gcc-on-windows/

How to Install the Latest GCC on Windows

Several modern C++ features are currently missing from Visual Studio Express, and from the system GCC compiler provided with many of today’s Linux distributions. Generic lambdas – also known as polymorphic lambdas – are one such feature. This feature is, however, available in the latest versions of GCC and Clang.

The following guide will help you install the latest GCC on Windows, so you can experiment with generic lambdas and other cutting-edge C++ features. You’ll need to compile GCC from sources, but that’s not a problem. Depending on the speed of your machine, you can have the latest GCC up and running in as little as 15 minutes.

The steps are:

  1. Install Cygwin, which gives us a Unix-like environment running on Windows.
  2. Install a set of Cygwin packages required for building GCC.
  3. From within Cygwin, download the GCC source code, build and install it.
  4. Test the new GCC compiler in C++14 mode using the -std=c++14 option.

[Update: As a commenter points out, you can also install native GCC compilers from the MinGW-w64 project without needing Cygwin.]

1. Install Cygwin

First, download and run either the 32- or 64-bit version of the Cygwin installer, depending on your version of Windows. Cygwin’s setup wizard will walk you through a series of steps. If your machine is located behind a proxy server, make sure to check “Use Internet Explorer Proxy Settings” when you get to the “Select Your Internet Connection” step.

When you reach the “Select Packages” step (shown below), don’t bother selecting any packages yet. Just go ahead and click Next. We’ll add additional packages from the command line later.

After the Cygwin installer completes, it’s very important to keep the installer around. The installer is an executable named either setup-x86.exe or setup-x86_64.exe, and you’ll need it to add or remove Cygwin packages in the future. I suggest moving the installer to the same folder where you installed Cygwin itself; typically C:\cygwin or C:\cygwin64.

If you already have Cygwin installed, it’s a good idea to re-run the installer to make sure it has the latest available packages. Alternatively, you can install a new instance of Cygwin in a different folder.

2. Install Required Cygwin Packages

Next, you’ll need to add several packages to Cygwin. You can add them all in one fell swoop. Just open a Command Prompt (in Windows), navigate to the folder where the Cygwin installer is located, and run the following command:

C:\cygwin64>setup-x86_64.exe -q -P wget -P gcc-g++ -P make -P diffutils -P libmpfr-devel -P libgmp-devel -P libmpc-devel

A window will pop up and download all the required packages along with their dependencies.

At this point, you now have a working GCC compiler on your system. It’s not the latest version of GCC; it’s whatever version the Cygwin maintainers chose as their system compiler. At the time of writing, that’s GCC 4.8.3. To get a more recent version of GCC, you’ll have to compile it yourself, using the GCC compiler you already have.

3. Download, Build and Install the Latest GCC

Open a Cygwin terminal, either from the Start menu or by running Cygwin.bat from the Cygwin installation folder.

If your machine is located behind a proxy server, you must run the following command from the Cygwin terminal before proceeding – otherwise, wget won’t work. This step is not needed if your machine is directly connected to the Internet.

$ export http_proxy=$HTTP_PROXY https_proxy=$HTTP_PROXY ftp_proxy=$HTTP_PROXY

To download and extract the latest GCC source code, enter the following commands in the Cygwin terminal. If you’re following this guide at a later date, there will surely be a more recent version of GCC available. I used 4.9.2, but you can use any version you like. Keep in mind, though, that it’s always best to have the latest Cygwin packages installed when building the latest GCC. Be patient with the tar command; it takes several minutes.

$ wget http://ftpmirror.gnu.org/gcc/gcc-4.9.2/gcc-4.9.2.tar.gz
$ tar xf gcc-4.9.2.tar.gz

That will create a subdirectory named gcc-4.9.2. Next, we’ll configure our GCC build. As the GCC documentation recommends, it’s best to configure and build GCC in another directory outside gcc-4.9.2, so that’s what we’ll do.

$ mkdir build-gcc
$ cd build-gcc
$ ../gcc-4.9.2/configure --program-suffix=-4.9.2 --enable-languages=c,c++ --disable-bootstrap --disable-shared

Here’s a description of the command-line options passed to configure:

  • The --program-suffix=-4.9.2 option means that once our new GCC is installed, we’ll run it as g++-4.9.2. This will make it easier for the new GCC compiler to coexist alongside the system GCC compiler provided by Cygwin.

  • The --enable-languages=c,c++ option means that only the C and C++ compilers will be built. Compilers for other languages, such as Fortran, Java and Go, will be excluded. This will save compile time.

  • The --disable-bootstrap option means that we only want to build the new compiler once. If we don’t specify --disable-bootstrap, the new compiler will be built three times, for testing and performance reasons. However, the system GCC compiler (4.8.3) provided by Cygwin is pretty recent, so --disable-bootstrap is good enough for our purposes. This will save a significant amount of compile time.

  • The --disable-shared option means that we don’t want to build the new standard C++ runtime library as a DLL that’s shared with other C++ applications on the system. It’s totally possible to make C++ executables work with such DLLs, but it takes care not to introduce conflicts with C++ executables created by older or newer versions of GCC. That’s something distribution maintainers need to worry about; not us. Let’s just avoid the additional headache.

  • By default, the new version of GCC will be installed to /usr/local in Cygwin’s virtual filesystem. This will make it easier to launch the new GCC, since /usr/local/bin is already listed in Cygwin’s PATH environment variable. However, if you’re using an existing Cygwin installation, it might prove difficult to uninstall GCC from /usr/local later on (if you so choose), since that directory tends to contain files from several different packages. If you prefer to install the new GCC to a different directory, add the option --prefix=/path/to/directory to the above configure command.

We’re not going to build a new Binutils, which GCC relies on, because the existing Binutils provided by Cygwin is already quite recent. We’re also skipping a couple of packages, namely ISL and CLooG, which means that the new compiler won’t be able to use any of the Graphite loop optimizations.

Next, we’ll actually build the new GCC compiler suite, including C, C++ and the standard C++ library. This is the longest step.

$ make -j4

The -j4 option lets the build process spawn up to four child processes in parallel. If your machine’s CPU has at least four hardware threads, this option makes the build process run significantly faster. The main downside is that it jumbles the output messages generated during the build process. If your CPU has even more hardware threads, you can specify a higher number with -j. For comparison, I tried various numbers on a Xeon-based machine having 12 hardware threads, and got the following build times:

Be warned: I encountered a segmentation fault the first time I ran with -j4. Bad luck on my part. If that happens to you, running the same command a second time should allow the build process to finish successfully. Also, when specifying higher numbers with -j, there are often strange error messages at the end of the build process involving “jobserver tokens”, but they’re harmless.

Once that’s finished, install the new compiler:

$ make install
$ cd ..

This installs several executables to /usr/local/bin; it installs the standard C++ library’s include files to /usr/local/include/c++/4.9.2; and it installs the static standard C++ library to /usr/local/lib, among other things. Interestingly, it does not install a new standard C library! The new compiler will continue to use the existing system C library that came with Cygwin.

If, later, you decide to uninstall the new GCC compiler, you have several options:

  • If you installed GCC to a directory other than /usr/local, and that directory contains no other files, you can simply delete that directory.
  • If you installed GCC to /usr/local, and there are files from other packages mixed into the same directory tree, you can run the list_modifications.py script from this post to determine which files are safe to delete from /usr/local.
  • You can simply uninstall Cygwin itself, by deleting the C:\cygwin64 folder in Windows, along with its associated Start menu entry.

4. Test the New Compiler

All right, let’s compile some code that uses generic lambdas! Generic lambdas are part of the C++14 standard. They let you pass arguments to lambda functions as auto (or any templated type), like the one highlighted below. Create a file named test.cpp with the following contents:

#include <iostream>

int main()
{
    auto lambda = [](auto x){ return x; };
    std::cout << lambda("Hello generic lambda!\n");
    return 0;
}

You can add files to your home directory in Cygwin using any Windows-based text editor; just save them to the folder C:\cygwin64\home\Jeff (or similar) in Windows.

First, let’s see what happens when we try to compile it using the system GCC compiler provided by Cygwin:

$ g++ --version
$ g++ -std=c++1y test.cpp

If the system compiler version is less than 4.9, compilation will fail:

Now, let’s try it again using our freshly built GCC compiler. The new compiler is already configured to locate its include files in /usr/local/include/c++/4.9.2 and its static libraries in /usr/local/lib. All we need to do is run it:

$ g++-4.9.2 -std=c++14 test.cpp
$ ./a.exe

It works!




本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

win10 安装 Cygwin 的相关文章

  • Typora 免费版下载安装(超简单亲测适用于Windows)与入门

    前言 Typora大家都知道 是一款好用的编辑器和阅读器 鬼鬼为大家找了一个可使用版本 安装过程十分简单 亲测有效 不浪费大家时间 现在将Typora分享给大家免费使用 下载链接在文章最后 目录 前言 一 Typora的介绍 MarkDow
  • 图的两种遍历方式dfs/bfs

    include
  • nodejs中express框架使用

    一 express介绍 express 是一个基于 Node js 平台的极简 灵活的 WEB 应用开发框架 express中文官网网址 https www expressjs com cn 简单来说 express 是一个封装好的工具包
  • C标准库的setlocale()用法笔记

    转自 http zyxhome org wp cc prog lang c stdlib setlocale usage note 在此向原文作者说声谢谢 若有读者看到文章转载时请写该转载地址 不要写我的BLOG地址 尊重他人的劳动成果 C
  • 计算机网络连接显示678是什么意思,宽带连接错误678,教您宽带连接出现错误提示代码678怎么解决...

    对电脑网络有资深了解的用户就知道 网络的错误代码678是宽带的故障代码之一 其含义是远程计算机无响应 而在网上罗列了一堆的可能性 其中涉及的一些高深的专业知识与判断 很多的用户都表示看得是云里雾里不知所云 下面 小编就给大家分享宽带连接出现
  • VScode连接服务器运行代码

    我的pycharm到期了 只能用VScode了 说一下怎么用VScode连接服务器 安装Remote SSH插件 设置 搜ssh 把这个打上对勾 这里建立新的连接 会让你输入 你需要输入username 地址 端口 输入完之后打开这个con
  • JS 判断当前浏览器是谷歌Google、火狐Firefox、Safari、Edge、Opera还是其他浏览器的方法

    JS 判断当前浏览器是谷歌Google 火狐Firefox Safari Edge还是其他浏览器的方法 如下 第一种 function detectBrowser const userAgent navigator userAgent if
  • Linux操作系统之C语言实现shell命令解释器项目

    文章目录 一 实现原理 二 具体实现过程 一 实现原理 普通命令 ls pwd cp clear 通过exec fork 内置命令 cd exit bash本身提供方法 调用自己的函数 不会产生子进程 二 具体实现过程 1 mybash项目
  • mockito

    mock 对接口返回值进行模拟数据 使用场景 1 协同开发的时候 需要调用未开发接口 模拟接口返回值数据 2 接口联调 网络不通的时候 把线上数据拷贝回来 模拟数据 添加mockito依赖
  • java用lambda函数排序,Java函数式编程-4.lambda表达式排序

    1 lambda表达式排序 咱们首先看几个比较常见的排序例子 基本数据类型的排序ide List list Arrays asList 1 3 2 5 4 list sort Comparator naturalOrder System o
  • cartographer更新地图-移除未完成的子图

    首先说明为什么要移除未完成的子图 因为如果不删除 每次更新都会保留以前未完成的子图 那时间累计数据量不断增长 不得了 overlapping submaps trimmer移除的只有已经完成的子图 那对于未完成的子图如何处理呢 首先在ove
  • tq210基本参数

    这个板子的核心板为core B 底板为tq210 board v4 1G ddr2 128Mx8pcs 1G slc flash K9K8G08 PMU TPS659101 使用系统自带的sd uboot 使用板子带的串口线 这个线与ok2
  • win10如何修改windows默认远程桌面端口号

    修改默认端口需要修改注册表 打开开始运行 输入regedit 进入注册编辑器 依次点击进入 HKEY LOCAL MACHINE SYSTEM CurrentContro1Set 接着找到 以下路径Control Tenninal Serv
  • NAT穿透 - P2P

    NAT穿透 P2P 一 NAT穿透 二 NAT分类 总结 一 NAT穿透 NAT穿透 即内网穿透 也称为打洞 其网络拓扑示例 二 NAT分类 完全锥型NAT 内网客户端映射到一个外部IP Port IP端口无限制 任意主机都可往该映射端口发
  • 逻辑分析题目:“给你一个9升的水桶和一个4升的水桶,在河里取6升水”

    问题答案 1 大桶装满 然后倒满小桶 这样大桶剩5升 小桶4升 2 小桶倒空 大桶再往小桶灌满 大桶剩1升 小桶4升 3 小桶倒空 把大桶的一升灌进小桶 这时大桶没有了 小桶一升 4 再灌满大桶 此时往已有1升得小桶里灌三升 大桶剩下6升
  • 算法训练Day38

    目录 动态规划理论基础 LeetCode509 斐波那契数 1 思路 2 代码实现 3 复杂度分析 4 总结与收获 LeetCode70 爬楼梯 1 思路 2 代码实现 3 复杂度分析 4 思考与收获 LeetCode746 使用最小花费爬
  • input/textarea文本的选择与获取

    获取input textarea中选择的文本function getSelectedText textbox if document selection IE return document selection createRange te
  • 网络与信息安全——知识整理(1)

    1 The Security Goals a Confidentiality to protect theconfidential information and to guard against the malicious actions
  • 数据结构——算法

    算法是什么 算法 Algorithm 是对解题方案的准确而完整的描述 是一系列解决问题的清晰指令 说白了就是 用来解决问题的 算法的特性 必须全部符合才可称之为一个算法 1 有穷性 一个算法必须在执行有穷步后结束且每一步必须在有穷时间内完成

随机推荐

  • Unity项目架构

    整理了一下Unity项目客户端涵盖一些内容 如果有遗漏 欢迎大家指出 感谢
  • 动画 + 大白话讲清楚React渲染原理

    前言 相信很多人跟我之前一样 看到源码两个字觉得触不可及 觉得离自己还很遥远 是需要非常多年的工作经验的大佬才能触及到的领域 就在去年我改变了这个想法 当时被react的几个生命周期执行顺序弄的睡不着觉 为什么有些时候生命周期的执行事与愿违
  • 小软件项目开发的管理

    小软件项目开发的管理 创建成功的工程 成功项目管理的秘密 更好地领导一个项目的诀窍 参与变革 走向成功 CMM TSP PSP讲义稿 开发流程中的可用性 软件开发的管理和控制 如何组织软件开发团队 软件项目管理 CMM 经验谈 实施CMM
  • stable-diffusion的webui和comfyuig共享模型路径

    1 修改上图extra model paths yaml example为extra model paths yaml Rename this to extra model paths yaml and ComfyUI will load
  • 最长公共子序列问题(Java)-动态规划

    动态规划法 经常会遇到复杂问题不能简单地分解成几个子问题 而会分解出一系列的子问题 简单地采用把大问题分解成子问题 并综合子问题的解导出大问题的解的方法 问题求解耗时会按问题规模呈幂级数增加 为了节约重复求相同子问题的时间 引入一个数组 不
  • 关于Springcloud的RestTemplate使用服务名报异常java.net.UnknownHostException

    关于Springcloud的RestTemplate使用服务名报异常java net UnknownHostException和使用localhost 8081报异常java lang IllegalStateException No in
  • ConstraintLayout基本使用之toLeftOf 、toTopOf、toRightOf、toBottomOf

    关于ConstraintLayout的博客 文章想必大家已经见过很多了 都是很全面的 今天这篇博客主要将ConstraintLayout的 layout constraintLeft toLeftOf layout constraintLe
  • HTML常考知识点和面试题

    保证页面不会出现编码问题 乱码 宽度等于设备宽度 初始化比例等于1 最大初始化比例等于1 user scalable no 将控制用户无法进行触屏扩大或缩小网页 适配移动端的第一步加上viewport 再针对手机屏幕大小调整 指定一个基础的
  • 【LeetCode队列】933 最近的请求次数 RecentCounter(java实现)

    文章目录 题目描述 一 解题思路 二 代码 1 最近的请求次数 2 测试数据 3 复杂度分析 4 执行时间 题目描述 写一个 RecentCounter 类来计算特定时间范围内最近的请求 请你实现 RecentCounter 类 Recen
  • 2023-04-29 读取内容为十六进制数字的txt文件转换为二进制文件

    读取内容为十六进制数字的txt文件转换为二进制文件 前言 一 示例代码 总结 前言 一个有趣的题目 读取txt文件内容两两结合 存储为dat文件 实现十分简单 有很多有意思的回答 但大都是python 其实这个用C的格式化读取fscanf
  • DC/DC:单端反激直流变换电路设计及matlab/Simulink仿真

    直流单端反激变换电路在开关管导通时电源将电能转为磁场能储存在变压器中 当开关管关断时再将磁能转变为电能传送到负载 单端反激变换电路是由升降压 Buck Boost 变换电路派生而来的 电路图如图所示 参数计算 理论计算可参考Buck Boo
  • 通过hyperledger fabric理解区块链存储

    hyperledger fabric 是一个联盟链框架 基于这个框架的最简单案例 A与B转账 我们来理解一下什么是区块链 第一个问题 区块链是干什么用的 很多人想到了比特币 以太坊等等 那具体是干什么用的呢 实际上可以理解为一个特别的数据存
  • ERROR: cannot launch node of type [map_server/map_server]: map_server等

    问题说明 在运行Autolabor simulation中README md的Quick start时 roslaunch simulation launch gmapping navigation launch 出现了以下错误 发现找不到
  • phpstudy安装和使用

    一 phpstudy 1 下载网址 http www xp cn 2 过程 1 往下拉可以看到推荐版本我下载的是8 1版本 注意下载路径不可以有中文或空格 2 按需下载 3 安装完成后解压 点击这个一步一步做就可以啦 3 简单熟悉phpst
  • 回形数(转载)

    转载及参考https blog csdn net sinat 37976731 article details 78614723 import java util Scanner author litianfu version 1 0 em
  • CCNP14-BGP基础

    文章目录 一 概念 二 特点 三 数据包 四 邻居关系 名词解释 五 BGP的防环机制 水平分割 六 BGP的工作过程 七 基本配置 八 BGP的三张表 1 简化邻居表 2 BGP的路由表 3 IP路由表 一 概念 BGP 边界网关协议 应
  • (4层)TCP 首部字段

    TCP 报文段的首部格式 TCP 虽然是面向字节流的 但 TCP 发送的数据单元却是报文段 一个 TCP 报文段分为首部和数据两部分 而 TCP 的全部功能都体现在它首部中各字段的作用 TCP 报文段首部的前 20 个字节是固定的 后面有
  • 【搭建博客】picGo+OSS防盗链配置(不同平台)

    汝之观览 吾之幸也 本文主要讲解在使用picGo OSS使用时会出现防盗链问题 配置OSS的防盗链 OSS支持对存储空间 Bucket 设置防盗链 即通过对访问来源设置白名单的机制 避免OSS资源被其他人盗用 可参考防盗链 配置目录 登录O
  • java strom实例_storm 入门教程+简单实例

    写在前面 本篇博客主要介绍 storm 基本概念和一个简单实例 storm版本1 0 2 storm基本概念 storm的集群架构 storm 是一个主从架构 一个主节点 n个从节点 主节点和从节点之间通过zk集群来进行交互 这张图是盗的
  • win10 安装 Cygwin

    http preshing com 20141108 how to install the latest gcc on windows How to Install the Latest GCC on Windows Several mod