当前位置: 首页 > 工具软件 > OpenBLAS > 使用案例 >

windows10 使用visual studio 2019编译OpenBLAS

云承弼
2023-12-01

参考:https://github.com/xianyi/OpenBLAS/wiki/How-to-use-OpenBLAS-in-Microsoft-Visual-Studio

下载anaconda :https://www.anaconda.com/products/individual

下载OpenBLAS:https://sourceforge.net/projects/openblas/files/     

                             http://www.openblas.net/

gitclone版编译时会报错”missing)“

打开anaconda shell输入下面指令

conda update -n base conda
conda config --add channels conda-forge
conda config --set channel_priority flexible
conda install -y cmake flang clangdev perl libflang ninja
  1. 安装成功之后把shell关掉,进入anaconda 安装路径\Library\bin找到clang-cl.exe这个程序,右键选择属性,然后选择兼容性,选中以管理员身份运行此程序并确认,否则会编译过程中会提示clang-cl.exe 报错
  2. 管理员身份重新打开Anaconda Prompt(Anaconda3)

 

输入下面指令,这一步很重要否则会报错找不到kernal**.lib的错误,设置vs运行环境为x64(注意:进入anaconda命令行后不要cd到其他目录下,直接在根目录下运行,否则会报错“找不到vcvars.bat”):

"c:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Auxiliary/Build/vcvars64.bat"

设置cmake 工程环境 mkdir build    cd build

set "LIB=%CONDA_PREFIX%\Library\lib;%LIB%"
set "CPATH=%CONDA_PREFIX%\Library\include;%CPATH%"
cmake .. -G "Ninja" -DCMAKE_CXX_COMPILER=clang-cl -DCMAKE_C_COMPILER=clang-cl -DCMAKE_Fortran_COMPILER=flang -DBUILD_WITHOUT_LAPACK=no -DNOFORTRAN=0 -DDYNAMIC_ARCH=ON -DCMAKE_BUILD_TYPE=Release

set 结束后可通过conda activate 查看设置,windows用户看不到结果

(base) C:\Windows\System32>conda activate

C:\Windows\System32>set "LIB="

C:\Windows\System32>set "CPATH="

C:\Windows\System32>set "_LIB="

C:\Windows\System32>set "_CPATH="

C:\Windows\System32>if "D:\ProgramData\Anaconda3" == "" set "LIB=;\Library\lib"

C:\Windows\System32>if "D:\ProgramData\Anaconda3" == "" set "CPATH=;\Library\include"

C:\Windows\System32>if not "D:\ProgramData\Anaconda3" == "" set "LIB=;D:\ProgramData\Anaconda3\Library\lib"

C:\Windows\System32>if not "D:\ProgramData\Anaconda3" == "" set "CPATH=;D:\ProgramData\Anaconda3\Library\include"

Build the project

cmake --build . --config release

Install all relevant files created by the build

cmake --install . --prefix "C:\Program Files (x86)\OpenBLAS" -v

新建环境变量  OpenBLAS_HOME    C:\Program Files (x86)\OpenBLAS

                        OpenBLAS     C:\Program Files (x86)\OpenBLAS

 类似资料: