C++ windows下四种编译器的编译指令以及如何配置

/*
    编译器编译指令
    MSVC        :cl /EHsc /std:c++latest /O2 parallel_sort.cpp /Femo.exe
    Intel C++   :icl /EHsc /std:c++latest /O2 parallel_sort.cpp /Feio.exe
    GNU g++     :g++ -std=c++2a -fopenmp -D_GLIBCXX_PARALLEL -O3 parallel_sort.cpp -o go.exe
    clang++     :clang++ -std=c++2a -O3 parallel_sort.cpp -o co.exe
*/

一、下载Visual Studio 2022 社区版本

地址:

二、下载MSYS2

地址:https://www.msys2.org/MSYS2Software Distribution and Building Platform for Windowshttps://www.msys2.org/

下载完成之后,打开MSYS2 MINGW64。

1、运行指令 panman -Syu

2、运行指令安装gcc

pacman -S mingw-w64-x86_64-gcc base-devel

3、运行指令安装clang

pacman -S mingw-w64-x86_64-clang base-devel

4、确定系统是否安装tbb

pacman -Ss tbb

5、安装tbb

pacman -S mingw-w64-x86_64-tbb

6、确定系统是否安装gmp

pacman -Ss gmp

7、安装gmp

pacman -S mingw-w64-x86_64-gmp

三、下载Visual Studio Code

地址:https://code.visualstudio.com/

四、下载C++ Library Extensions

地址:

四、下载Intel oneAPI Threading Building Blocks Alone for use with MSVC++

1、下载

Intel® oneAPI standalone component installation filesIntel® oneAPI standalone component installation fileshttps://www.intel.com/content/www/us/en/developer/articles/tool/oneapi-standalone-components.html#onetbb

 安装之后将其include文件添加到系统环境变量中。

2、配置到MSVC++

在桌面上新建msvc-vars.bat文件,其内容设置为

@echo off

call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"

call "C:\Program Files (x86)\Intel\oneAPI\tbb\2021.8.0\env\vars.bat" intel64 vs2019

echo For Microsoft Visual C++ Compiler

设置完成之后,将smvc-vars.bat文件拷贝到C:/Windows/目录下

在桌面上复制一份vs2022的 x64 Native Tools Command Prompt for VS 2022的快捷方式,将其重命名为x64 MSVC,右键,选择属性,并将其目标和起始位置设置如下:

起始位置:表示运行x64 MSVC,控制台的起始位置。

五、下载Intel oneAPI Threading Building Blocks Alone for use with GNU g++ and clang

1、打开MSYS2 MINGW64,安装tbb

pacman -S mingw-w64-x86_64-tbb

pacman -S mingw-w64-clang-x86_64-tbb

2、配置到GNU clang

 在桌面上新建gnu-vars.bat文件,其内容设置为

@echo off

call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"

set PATH=%GNU_PATH%;%PATH%

echo For GNU g++ and LLVM clang++

设置完成之后,将gnu-vars.bat文件拷贝到C:/Windows/目录下

在系统环境中添加新的变量,

GUN_PATH = C:\DevSoft\msys64\bin;C:\DevSoft\msys64\mingw64\bin;

CPLUS_INCLUDE_PATH = C:\DevSoft\CppExtension\include;

在桌面上复制一份vs2022的 x64 Native Tools Command Prompt for VS 2022的快捷方式,将其重命名为x64 GNU CLANG,右键,选择属性,并将其目标和起始位置设置如下:

起始位置:表示运行x64 GNU CLANG,控制台的起始位置。

 

#include <tbb/tbb.h>
#include <iostream>


// cl /EHsc /std:c++17 hello.cpp tbb12.lib /Fe: m.exe
// clang++ -std=c++17 hello.cpp -ltbb12 -o c.exe
// g++ -std=c++17 hello.cpp -ltbb12 -o g.exe

int main()
{
    auto task1 = [](){ std::cout<< "Hello, World 1!" << std::endl; };
    auto task2 = [](){ std::cout<< "Hello, World 2!" << std::endl; };

    tbb::parallel_invoke(task1, task2);
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值