C++ 编译环境

让人想犯罪 __ 提交于 2019-12-04 01:55:20

1  面向 Linux 和 Windows

操作系统:CentOS 7

1.1  安装 CentOS 7

http://mirrors.ustc.edu.cn/centos/7/isos/x86_64/CentOS-7-x86_64-Minimal-1810.iso

yum install epel-release
yum update
yum install wget zip unzip

1.2  Linux 64-bit

yum install gcc gcc-c++ gcc-gfortran
yum install glibc-static libstdc++-static libgfortran-static
yum install boost-static
yum install blas-static lapack-static
yum install qt5-qtbase-devel

MKL 链接方式

MKLROOT=/opt/intel/mkl
MKLLIB=${MKLROOT}/lib/intel64

LIB1=${MKLLIB}/libmkl_intel_lp64.a
LIB2=${MKLLIB}/libmkl_sequential.a
LIB3=${MKLLIB}/libmkl_core.a

LDLIBS += -Wl,--start-group $LIB1 $LIB2 $LIB3 -Wl,--end-group -lpthread -lm -ldl

1.3  Windows 64-bit

yum install mingw64-gcc mingw64-gcc-c++ mingw64-gcc-gfortran
yum install mingw64-libgomp mingw64-winpthreads-static
yum install mingw64-boost-static
yum install mingw64-qt-static

编译 LAPACK

LAPACK=lapack-3.8.0

rm -rf $LAPACK
tar zxf $LAPACK.tar.gz
cd $LAPACK

cp make.inc.example make.inc
sed -i "s/= gfortran/= x86_64-w64-mingw32-gfortran/" make.inc
sed -i "s/= ar/= x86_64-w64-mingw32-ar/" make.inc
sed -i "s/= ranlib/= x86_64-w64-mingw32-ranlib/" make.inc

make blaslib lapacklib
cp librefblas.a liblapack.a /usr/x86_64-w64-mingw32/sys-root/mingw/lib

1.4  Windows 32-bit

yum install mingw32-gcc mingw32-gcc-c++ mingw32-gcc-gfortran
yum install mingw32-libgomp mingw32-winpthreads-static
yum install mingw32-boost-static
yum install mingw32-qt-static

编译 LAPACK

LAPACK=lapack-3.8.0

rm -rf $LAPACK
tar zxf $LAPACK.tar.gz
cd $LAPACK

cp make.inc.example make.inc
sed -i "s/= gfortran/= i686-w64-mingw32-gfortran/" make.inc
sed -i "s/= ar/= i686-w64-mingw32-ar/" make.inc
sed -i "s/= ranlib/= i686-w64-mingw32-ranlib/" make.inc

make blaslib lapacklib
cp librefblas.a liblapack.a /usr/i686-w64-mingw32/sys-root/mingw/lib

2  面向 macOS

操作系统:macOS Mojave

2.1  安装命令行工具

xcode-select --install

2.2  安装 Homebrew

https://brew.sh/

https://raw.githubusercontent.com/Homebrew/install/master/install

替换 BREW_REPO = "https://github.com/Homebrew/brew"

为 BREW_REPO = "http://mirrors.ustc.edu.cn/brew.git/"

export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles

2.3  安装 LLVM

brew install llvm@7 libomp boost qt
rm /usr/local/opt/libomp/lib/*.dylib
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

Clang 环境变量

export PATH="/usr/local/opt/llvm@7/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/llvm@7/lib"
export CPPFLAGS="-I/usr/local/opt/llvm@7/include"

OpenMP 命令行

-fopenmp

LAPACK 命令行

-framework Accelerate

MKL 链接方式

MKLROOT=/opt/intel/mkl
MKLLIB=${MKLROOT}/lib

LIB1=${MKLLIB}/libmkl_intel_lp64.a
LIB2=${MKLLIB}/libmkl_sequential.a
LIB3=${MKLLIB}/libmkl_core.a

LDLIBS += $LIB1 $LIB2 $LIB3 -lpthread -lm -ldl
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!