-
Notifications
You must be signed in to change notification settings - Fork 1.6k
How to use OpenBLAS in Microsoft Visual Studio
As of OpenBLAS v0.2.15, we support MinGW and Visual Studio (using CMake to generate visual studio solution files) to build OpenBLAS on Windows.
##1. MinGW
The resulting library can be used in Visual Studio, but it can only be linked dynamically. This configuration has not been thoroughly tested and should be considered experimental.
Due to incompatibilities between the calling conventions of MinGW and Visual Studio you will need to make the following modifications ( 32-bit only ):
- Use the newer GCC 4.7.0. The older GCC (<4.7.0) has an ABI incompatibility for returning aggregate structures larger than 8 bytes with MSVC.
- Install the MinGW (GCC) compiler suite, either 32-bit (http://www.mingw.org/) or 64-bit (http://mingw-w64.sourceforge.net/). In addition, please install MSYS with MinGW.
- Build OpenBLAS in the MSYS shell. Usually, you can just type "make". OpenBLAS will detect the compiler and CPU automatically.
- After the build is complete, OpenBLAS will generate the static library "libopenblas.a" and the shared dll library "libopenblas.dll" in the folder. You can type "make PREFIX=/your/installation/path install" to install the library to a certain location.
[Notice] We suggest using official MingWin or MingWin-w64 compilers. A user reported that s/he met Unhandled exception
by other compiler suite. https://groups.google.com/forum/#!topic/openblas-users/me2S4LkE55w
- First, you will need to have the
lib.exe
tool in the Visual Studio command prompt. - Open the command prompt and type
cd OPENBLAS_TOP_DIR/exports
, where OPENBLAS_TOP_DIR is the main folder of your OpenBLAS installation. - For a 32-bit library, type
lib /machine:i386 /def:libopenblas.def
. For 64-bit, typelib /machine:X64 /def:libopenblas.def
. - This will generate the import library "libopenblas.lib" and the export library "libopenblas.exp" in OPENBLAS_TOP_DIR/exports. Although these two files have the same name, they are totally different.
- OpenBLAS already generated the import library "libopenblas.dll.a" for "libopenblas.dll".
- Copy the import library (before 0.2.10: "OPENBLAS_TOP_DIR/exports/libopenblas.lib", 0.2.10 and after: "OPENBLAS_TOP_DIR/libopenblas.dll.a") and .dll library "libopenblas.dll" into the same folder(The folder of your project that is going to use the BLAS library. You may need to add the libopenblas.dll.a to the linker input list: properties->Linker->Input).
- Please follow the documentation about using third-party .dll libraries in MS Visual Studio 2008 or 2010. Make sure to link against a library for the correct architecture. For example, you may receive an error such as "The application was unable to start correctly (0xc00007b)" which typically indicates a mismatch between 32/64-bit libraries.
[Notice] If you need CBLAS, you should include cblas.h in /your/installation/path/include in Visual Studio. Please read this page.
- Both static and dynamic linking are supported with MinGW. With Visual Studio, however, only dynamic linking is supported and so you should use the import library.
- Debugging from Visual Studio does not work because MinGW and Visual Studio have incompatible formats for debug information (PDB vs. DWARF/STABS). You should either debug with GDB on the command-line or with a visual frontend, for instance Eclipse or Qt Creator.
##2. CMake and Visual Studio
Since OpenBLAS 0.2.15 version, we support CMake experimentally. The user can use CMake at Windows, Linux, or Mac OSX. For Windows, we tested the library with Visual Studio 2012 and 2013.
[Notice] Because Visual Studio cannot recognize AT&T assembly language, OpenBLAS only uses the C kernels for Visual Studio native build. Thus, the performance is not good compared to MinGW build.
##1. Install CMake at Windows ##2. Use CMake to generate Visual Studio solution files
# do this from powershell so cmake can find visual studio
cmake -G "Visual Studio 14 Win64" .
##3. Build the solution at Visual Studio
Note that this step depends on perl, so you'll need to install perl for windows, and put perl on your path so VS can start perl (http://stackoverflow.com/questions/3051049/active-perl-installation-on-windows-operating-system).
Step 2 will build the OpenBLAS solution, open it in VS, and build the projects. Note that the dependencies do not seem to be automatically configured: if you try to build libopenblas directly, it will fail with a message saying that some .obj files aren't found, but if you build the projects libopenblas depends on before building libopenblas, the build will succeed.