Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set linker type(with or without underscore as suffix) for BLAS complied by MinGW64? #986

Open
mygit2hub opened this issue Feb 18, 2024 · 1 comment

Comments

@mygit2hub
Copy link

mygit2hub commented Feb 18, 2024

To install CHOLMOD, the following sources and tools are used to bulid libblas.lib and liblapack.lib in Windows 10.


LAPACK 3.12.0
Win64 version: GCC 13.2.0 (with POSIX threads) + LLVM/Clang/LLD/LLDB 17.0.6 + MinGW-w64 11.0.1 (UCRT) - release 5 (at https://winlibs.com/)


Following the "Build Instructions to create LAPACK and LAPACKE 3.5.0 dlls for Windows with MinGW" below (at https://icl.utk.edu/lapack-for-windows/lapack/index.html#libraries), libblas.lib, liblapack.lib, and .DLLs can be gained.


Requirements: MinGW, CMAKE 2.8.12, VS IDEs
1.Download the lapack.tgz from the netlib website and unzip.
2.Download CMAKE and install it on your machine.
3.Download MinGW 32 bits or MinGW-w64 and install it on your machine.
4.Put the GNU runtime directory in your PATH, for me I added C:\MinGW\bin (MinGW 32 bits) in my PATH (right click on your computer icon, go to properties, advanced system settings, Environment Variables, look for the PATH variable and put 'C:\MinGW\bin;' in front of its current value)
5.Open CMAKE
Point to your lapack-3.5.0 folder as the source code folder
Point to a new folder where you want the build to be (not the same is better)
Click configure, check the install path if you want to have the libraries and includes in a particular location.
Choose MinGW Makefiles.
Click "Specify native compilers" and indicate the path to the Mingw compilers.
For Win32, on my machine, the Fortran Compiler is "C:/MinGW/bin/gfortran.exe", and the C compiler is "C:/MinGW/bin/gcc.exe"
For x64, on my machine, it is "C:/mingw64/bin/x86_64-w64-mingw32-gfortran.exe" and the C compiler is "C:/mingw64/bin/x86_64-w64-mingw32-gcc.exe"
For x64 build ONLY , add the variable CMAKE_SIZEOF_VOID_P and set it to 8 (string), this will force CMAKE to create the VCVARSAMD64 variable ( see post on forum) Note: CMAKE team corrected the issue, and thus this workaround won't be needed if you are using CMAKE 2.8.13 or above
Click "Specify native compilers" and indicate the path to the Mingw compilers. On my machine, it is "C:/MinGW/bin/gfortran.exe"
Set the 'BUILD_SHARED_LIBS' option to ON.
Set the 'CMAKE_GNUtoMS' option to ON.
if you want to build the LAPACKE library, set the 'LAPACKE' option to ON.
Click again configure until everything becomes white
Click generate, that will create the mingw build.
Close CMAKE
6. Open a cmd prompt (Click Run.. then enter cmd)
7. Go to your build folder using the cd command
8. Type C:/MinGW/bin/mingw32-make.exe
9. Type C:/MinGW/bin/mingw32-make.exe test if you want to run LAPACK testings to make sure everything is ok
10. Your libs are in the lib folder, the dlls are in the bin folder. The resulting build will provide both GNU-format and MS-format import libraries for the DLLs.
11. Now you should be able to create a C application built with MSVC and linked directly to the MinGW-built LAPACK DLLs
12. NOTE: Your C application built with Microsoft Visual Studio and linked to the MinGW-built lapack DLLs will run but requires the GNU runtime DLLs ( both libgfortran-3.dll and libgcc_s_dw2-1.dll are needed.) from MinGW to be available. As you have the GNU runtime directory in your PATH, you should be good to go.
13. Do not forget to consult also the LAPACKE User Guide.


The liblapack.dll and libblas.dll for BLAS and Lapack were checked that the Fortran functions such as dtrsv, dgemv, dtrsm, dgemm cannot be linked by MSVS 2019(error LNK2019: unresolved external symbol dtrsm referenced in function rd_cholmod_super_numeric_worker), for the mingw32-make complier appending an underscore for each function as suffix (i.e, dtrsv_), which is confirmed by opening the file libblas.dll.

Maybe using the default command mingw32-make.exe, the .lib and .dll are built with underscore suffix for each function. I wonder if the command mingw32-make.exe needs to be changed with certain options to mangling the symbol '_' in the libs and dlls. Or some variables or entries in cmake files need to be preset?

@martin-frbg
Copy link
Collaborator

Try adding -fno-underscoring to your Fortran compiler flags

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants