1、下载OpenBlas ( http://www.openblas.net/ )待编译
2、安装MSYS2,MSYS的重写项目,是MinGW提供的一个小型的GNU环境,包括基本的bash,make,还有pacman工具进行软件包的管理等等。简单说MSYS就相当于一个在Windows下运行的linux bash shell环境
安装MSYS2很简单,去这里下载.tar.xz或.exe http://repo.msys2.org/distrib/
3、安装MinGW编译器(通过pacman就可以安装mingw-w64提供的mingw编译器。)
# 安装 mingw64 64位编译器
$ pacman -S mingw-w64-x86_64-gcc
# 安装 mingw32 32位编译器
$ pacman -S mingw-w64-i686-gcc
4、编译OpenBlas
a、进入MSYS2 shell
b、在Msys2 shell中进入OpenBlas目录,输入make即可开始编译,OpenBlas会自动检测编译器和CPU,最后显示如下:
make[1]: 离开目录“/f/xianyi-OpenBLAS-eebc189/exports”
OpenBLAS build complete. (BLAS CBLAS)
OS ... CYGWIN_NT
Architecture ... x86_64
BINARY ... 64bit
C compiler ... GCC (command line : cc)
Library Name ... cygopenblas_haswellp-r0.3.5.a (Multi threaded; Max num-threads is 2)
To install the library, you can run "make PREFIX=/path/to/your/installation install".
c、编译完成后,在OpenBlas目录下,会出现libopenblas.a和libopenblas.dll两个文件,安装一下命令将编译好的OpenBlas库安装到系统中去:
$ make PREFIX=/f/xianyi-OpenBLAS-eebc189 install
make -j 2 -f Makefile.install install
make[1]: 进入目录“/f/xianyi-OpenBLAS-eebc189”
Generating openblas_config.h in /f/xianyi-OpenBLAS-eebc189/include
Generating f77blas.h in /f/xianyi-OpenBLAS-eebc189/include
Generating cblas.h in /f/xianyi-OpenBLAS-eebc189/include
Copying the static library to /f/xianyi-OpenBLAS-eebc189/lib
Copying the shared library to /f/xianyi-OpenBLAS-eebc189/lib
Generating openblas.pc in /f/xianyi-OpenBLAS-eebc189/lib/pkgconfig
Generating OpenBLASConfig.cmake in /f/xianyi-OpenBLAS-eebc189/lib/cmake/openblas
Generating OpenBLASConfigVersion.cmake in /f/xianyi-OpenBLAS-eebc189/lib/cmake/openblas
Install OK!
make[1]: 离开目录“/f/xianyi-OpenBLAS-eebc189”
本步骤即是提取、生成所需的头文件、库文件到f/xianyi-OpenBLAS-eebc189文件夹中,会生成include、bin、lib文件夹
C:\Users\10596\Desktop\临时文件\c++\oj\ConsoleApplication1\ConsoleApplication1>f:
F:\>cd F:\xianyi-OpenBLAS-eebc189\exports
F:\xianyi-OpenBLAS-eebc189\exports>lib /machine:X64 /def:libopenblas.def
Microsoft (R) Library Manager Version 14.00.23506.0
Copyright (C) Microsoft Corporation. All rights reserved.
LINK : fatal error LNK1104: 无法打开文件“libopenblas.def”
F:\xianyi-OpenBLAS-eebc189\exports>lib /machine:X64 /def:cygopenblas.def
Microsoft (R) Library Manager Version 14.00.23506.0
Copyright (C) Microsoft Corporation. All rights reserved.
正在创建库 cygopenblas.lib 和对象 cygopenblas.exp
d、在vs中添加包含目录\include,库目录\lib,附加依赖项\lib 中libopenblas.lib,在PATH环境变量中添加\path\bin文件夹的路径,在cmd内输入 set PATH='C:\'以强制电脑刷新环境变量;
附:
参考链接:
Windows下MSYS2中编译OpenBLAS过程记录(里面提到用shell脚本编译OpenBLAS,给出具体参数,但没有走通)
Windows 中OpenBlas 的安装 - Windows 32bit 适用(讲到系统生成include、lib、bin
将路径添加到vs和path)
1、使环境变量生效
打开命令提示符 CMD,运行 set PATH=C:
,更改当前窗口任务的环境变量,关闭这个 CMD。
再次打开另一个 CMD,运行 echo %PATH%
,显示最新的环境变量,会发现刚刚添加的 MinGW 环境变量已经生效。
2、shell脚本建立与执行
新建helloworld.sh
[root@centos6-1 ~]# touch helloworld.sh1
编辑helloworld.sh文件,添入一下内容
#!/bin/bash
echo "helloworld"12
#! 是一个约定的标记,它告诉系统这个脚本需要什么解释器来执行,即使用哪一种Shell,这里指定bash
echo 是Shell的一个内部指令,用于在屏幕上打印出指定的字符串
赋予当前用户helloworld.sh的执行权限(刚创建的文件没有执行权限)
[root@centos6-1 ~]# chmod u+x helloworld.sh1
执行hellowo.sh脚本方式一
[root@centos6-1 ~]# ./helloworld.sh
helloworld
[root@centos6-1 ~]# 123
注意,一定要写成./helloworld.sh,而不是helloworld.sh,linux系统会去PATH里寻找有没有叫helloworld.sh的,而helloworld.sh不在PATH里,所以写成helloworld.sh是会找不到命令的,要用./helloworld.sh告诉系统说,就在当前目录找。
执行hellowo.sh脚本方式二
[root@centos6-1 ~]# /bin/sh helloworld.sh
helloworld
[root@centos6-1 ~]#
此部分原文:https://blog.csdn.net/weixin_37490221/article/details/80869792