在docker里使用gcc-9 + tbb搭建CC++并行开发环境

在docker里使用gcc-9 + tbb搭建CC++并行开发环境,第1张

在docker里使用gcc-9 + tbb搭建C/C++并行开发环境

通过vscode提供的远程开发插件,在MacOS里安装ubuntu的docker容器,并在容器中进行c/c++开发。记录环境配置过程:

  1. 下载ubuntu 18.04 容器镜像(主机内)
    docker pull ubuntu:18.04
    
    docker run -idt --name ubdev --memory-swap=-1 ubuntu:20.04
    #设置swap参数是为了gcc-11的编译
  2. 进入容器内
    docker exec -it ubdev /bin/bash
  3. 安装依赖库(容器内)
    apt-get update
    apt install software-properties-common
  4. 下载并安装gcc-9(容器内) 
    apt-get install software-properties-common
    add-apt-repository ppa:jonathonf/gcc
    apt-get update
    apt-get install gcc-9
    
  5. 安装tbb
    wget https://github.com/intel/tbb/archive/2019_U8.tar.gz
    tar zxvf oneTBB-2019_U8.tar.gz
    mv oneTBB-2019_U8 tbb-2019_U8
    cd tbb-2019_U8
    
    
    
    cp build/linux.gcc.inc build/linux.gcc-9.inc 
    # 编辑build/linux.gcc-9.inc文件,可以拷贝到容器外面修改后在拷贝进来
    # 找到下面的语句修改改 g++-9 gcc-9
    CPLUS ?= g++-9
    ConLY ?= gcc-9
    
    #编译tbb
    make compiler=gcc-9 stdver=c++17 tbb_build_prefix=my_tbb_build
    
    #手动安装
    mkdir /usr/local/tbb-2019_U8
    cp -r include /usr/local/tbb-2019_U8/include
    ln -s /usr/local/tbb-2019_U8/include/tbb /usr/local/include/tbb
    cp -r build/my_tbb_build_release /usr/local/tbb-2019_U8/lib
     
    ln -s /usr/local/tbb-2019_U8/lib/libtbb.so.2 /usr/local/lib/libtbb.so
    ln -s /usr/local/tbb-2019_U8/lib/libtbbmalloc.so.2 /usr/local/lib/libtbbmalloc.so
    ln -s /usr/local/tbb-2019_U8/lib/libtbbmalloc_proxy.so.2 /usr/local/lib/libtbbmalloc_proxy.so
    echo 'export LD_LIBRARY_PATH=/usr/local/tbb-2019_U8/lib:$LD_LIBRARY_PATH' >> ~/.bashrc
    source ~/.bashrc

  6. 打开vscode(主机内)
      
  7. 编译task的参数如下
    {
        "tasks": [
            {
                "type": "cppbuild",
                "label": "C/C++: g++-9 build active file",
                "command": "/usr/bin/g++-9",
                "args": [
                    "-g",
                    "-std=c++17",
                    "${file}",
                    "-o",
                    "${fileDirname}/${filebasenameNoExtension}",
                    "-ltbb",
                    "-L /usr/local/lib"
                ],
                "options": {
                    "cwd": "${fileDirname}"
                },
                "problemMatcher": [
                    "$gcc"
                ],
                "group": {
                    "kind": "build",
                    "isDefault": true
                },
                "detail": "Task generated by Debugger."
            }
        ],
        "version": "2.0.0"
    }

 

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5521002.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-13
下一篇 2022-12-13

发表评论

登录后才能评论

评论列表(0条)

保存