-
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.3, it is currently only possible on Windows to build OpenBLAS with 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.
-
Force the use of G77 calling conventions:
--- a/Makefile.system
+++ b/Makefile.system
@@ -382,7 +382,7 @@
endif
ifeq ($(F_COMPILER), GFORTRAN)
-CCOMMON_OPT += -DF_INTERFACE_GFORT
+CCOMMON_OPT += -DF_INTERFACE_G77
FCOMMON_OPT += -Wall
EXTRALIB += -lgfortran
ifdef NO_BINARY_MODE
- Ensure the correct stack alignment:
--- a/Makefile.rule
+++ b/Makefile.rule
@@ -118,6 +118,9 @@ else
COMMON_OPT += -O2
endif
+# Stack alignment: compatibility with Visual Studio
+COMMON_OPT += -mincoming-stack-boundary=2
+
# Profiling flags
COMMON_PROF = -pg
Further details on why this is necessary are listed here: http://list.rdcps.ac.cn/pipermail/openblas/2012-May/000082.html
- 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.lib" 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.
- 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.
- Copy the import library "OPENBLAS_TOP_DIR/exports/libopenblas.lib" and .dll library "libopenblas.dll" into the same folder.
- 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.