I'd like to instruct CMake to instruct mingw-w64 to create a *.lib for the shared *.dll C library
I'm trying to cross compile a lapack.dll (and the accompanying lapack.lib) from the lapack project
https://github.com/Reference-LAPACK/lapack
The resulting shared lib should be usable by MSVC (so I don't need to setup a fortran compiler on Windows). MSVC needs a *.lib implib to link to the dll
I don't want to set custom CMAKE_Fortran_COMPILE_FLAGS if I can avoid it. Also the created lapack-config.cmake file should link to the *.lib file instead of the now generated *.dll.a file.
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Child items ...
Show closed items
Linked items 0
Link issues together to show that they're related.
Learn more.
cmake_minimum_required(VERSION 3.1)project(LAPACK Fortran C)
linux-mingw-w64.cmake
set(CMAKE_SYSTEM_NAME Windows)set(CMAKE_SYSTEM_PROCESSOR x86_64)set(TOOLCHAIN_PREFIX x86_64-w64-mingw32)# set compilerset(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)set(CMAKE_Fortran_COMPILER ${TOOLCHAIN_PREFIX}-gfortran)set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)# target environment on the build host system# set 1st to dir with the cross compiler's C/C++ headers/libsset(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})# modify default behavior of FIND_XXX() commands to# search for headers/libs in the target environment and# search for programs in the build host environmentset(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)# use emulator for `try_run` callsset(CMAKE_CROSSCOMPILING_EMULATOR wine64)
steps to reproduce (tested on Ubuntu 18.04)
install gfortran-mingw-64
sudo apt install cmake gfortran-mingw-w64
configure project to cross compile with mingw and set CMAKE_GNUtoMS variable
error and configure output. Tested on cmake 3.10 (default on Ubuntu 18.04) and 3.14.2
-- The Fortran compiler identification is GNU 7.3.0-- The C compiler identification is GNU 7.3.0-- Check for working Fortran compiler: /usr/bin/x86_64-w64-mingw32-gfortran-- Check for working Fortran compiler: /usr/bin/x86_64-w64-mingw32-gfortran -- works-- Detecting Fortran compiler ABI info-- Detecting Fortran compiler ABI info - done-- Checking whether /usr/bin/x86_64-w64-mingw32-gfortran supports Fortran 90-- Checking whether /usr/bin/x86_64-w64-mingw32-gfortran supports Fortran 90 -- yesCMake Error at /usr/share/cmake-3.14/Modules/Platform/Windows-GNU.cmake:156 (cmake_host_system_information): cmake_host_system_information does not recognize <key> VS_15_DIRCall Stack (most recent call first): /usr/share/cmake-3.14/Modules/Platform/Windows-GNU-Fortran-ABI.cmake:1 (__windows_compiler_gnu_abi) /usr/share/cmake-3.14/Modules/CMakeTestFortranCompiler.cmake:98 (include) CMakeLists.txt:3 (project)CMake Warning at /usr/share/cmake-3.14/Modules/Platform/Windows-GNU.cmake:199 (message): Disabling CMAKE_GNUtoMS option because CMAKE_GNUtoMS_VCVARS is not set.Call Stack (most recent call first): /usr/share/cmake-3.14/Modules/Platform/Windows-GNU-Fortran-ABI.cmake:1 (__windows_compiler_gnu_abi) /usr/share/cmake-3.14/Modules/CMakeTestFortranCompiler.cmake:98 (include) CMakeLists.txt:3 (project)-- Check for working C compiler: /usr/bin/x86_64-w64-mingw32-gcc-- Check for working C compiler: /usr/bin/x86_64-w64-mingw32-gcc -- works-- Detecting C compiler ABI info-- Detecting C compiler ABI info - done-- Detecting C compile features-- Detecting C compile features - done-- Configuring incomplete, errors occurred!See also "/home/neroburner/minimum_GNUtoMS/_build_mingw/CMakeFiles/CMakeOutput.log".
@brad.king is the CMAKE_GNUtoMS variable a Windows only thing and I do need to have the Visual Studio Compiler installed alongside mingw? That would mean I can't use the variable when cross compiling (with windows as target platform)
@NeroBurner yes I think so. The GNUtoMS implementation requires MS tools to be installed in order to produce the MS-format files. If suitable tools are available on Linux then perhaps it could be taught to use them, but I don't know of any such tools off the top of my head.
You need to set the CMAKE_GNUtoMS variable to ON to indicate CMake/Mingw to convert GNU import library (.dll.a) to MS format (.lib) and you need to set CMAKE_GNUtoMS_VCVARS with path to filevcvarsall.bat too.
Did you see this warning?
CMake Warning at /usr/share/cmake-3.14/Modules/Platform/Windows-GNU.cmake:199 (message): Disabling CMAKE_GNUtoMS option because CMAKE_GNUtoMS_VCVARS is not set.
Setting up these two variables is sufficient to CMake/Mingw generate a MS format shared library (.lib and .dll). But, the lapack.dll will need to some Mingw .dlls too!
See, this is the lapack lib folder compiled with Mingw and with these two variables setted:
And this is the bin folder with Lapack and Mingw DLLs:
I tested the Lapack Library in a sample project that generate two executables:
-- Selecting Windows SDK version to target Windows 10.0.17134.-- The CXX compiler identification is MSVC 19.0.24215.1-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe -- works-- Detecting CXX compiler ABI info-- Detecting CXX compiler ABI info - done-- Detecting CXX compile features-- Detecting CXX compile features - done-- Conan: called by CMake conan helper-- Conan: Using cmake global configuration-- Conan: Adjusting language standard-- Configuring done-- Generating done-- Build files have been written to: C:/Users/petro/Documents/conan-recipes/lapack/3.7.1/test_package/build/075b7aaf8aae75e822da5a48751d1fb7465f3e73[Build messages...][Successful build][Running executables]lapack/3.7.1@petrosoft/stable (test package): *** Executing bin/xexample_DGELS_colmajor.exe ... Entry Matrix A 1.00 1.00 1.00 2.00 3.00 4.00 3.00 5.00 2.00 4.00 2.00 5.00 5.00 4.00 3.00 Right Hand Side b -10.00 -3.00 12.00 14.00 14.00 12.00LAPACKE_dgels (col-major, high-level) Example Program Results ** On entry to DGELS parameter number 8 had an illegal valuelapack/3.7.1@petrosoft/stable (test package): *** Executing bin/xexample_DGELS_rowmajor.exe ... Entry Matrix A 1.00 1.00 1.00 2.00 3.00 4.00 3.00 5.00 2.00 4.00 2.00 5.00 5.00 4.00 3.00 Right Hand Side b -10.00 -3.00 12.00 14.00 14.00 12.00LAPACKE_dgels (row-major, high-level) Example Program Results ** On entry to DGELS parameter number 6 had an illegal value
I hope that I helped you and sorry for my poor English skills!