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

HiGHS Supplying a *.lib File Instead of the libhighs.dll.a #777

Closed
jeffreydeankelly2 opened this issue Mar 23, 2022 · 13 comments
Closed

HiGHS Supplying a *.lib File Instead of the libhighs.dll.a #777

jeffreydeankelly2 opened this issue Mar 23, 2022 · 13 comments
Labels
enhancement New feature or request

Comments

@jeffreydeankelly2
Copy link

Hi All;

When downloading the HiGHS binaries, only a libhighs.dll.a file is provided in the LIB sub-directory.

I am wondering if you can supply a *.lib file as well as part of your installation?

Our software has interfaced the following third-party solvers and all of them supply a *.lib file as their standard / default binary file install.

We statically link these *.lib files using Intel Fortran via its Fortran-C interoperability capability.

COINMP, GLPK, LPSOLVE, SCIP, IPOPT, CONOPT, KNITRO, LINDO, MOSEK, GUROBI, CPLEX, XPRESS and OPTONOMY.

Of course at runtime if the corresponding *.dll is not found, then an exception is raised.

All the best - Jeff

@odow
Copy link
Collaborator

odow commented Mar 23, 2022

The current binaries are not maintained by the core HiGHS team. We dynamically link things for use in Julia, but these binaries can also be used outside of Julia.

Do you only want static windows binaries? We had a look at compiling static libraries, but it gets complicated across all systems because it pulls in GPL software on linux.

HiGHS is also pretty easy to compile, so it shouldn't be hard to add that to your build system.

See also: #746

@jeffreydeankelly2
Copy link
Author

jeffreydeankelly2 commented Mar 23, 2022 via email

@odow
Copy link
Collaborator

odow commented Mar 23, 2022

Do you only want static windows binaries?

I meant, is your application distributed on Windows only, or do you also ship macOS and linux?

@jeffreydeankelly2
Copy link
Author

jeffreydeankelly2 commented Mar 23, 2022 via email

@odow
Copy link
Collaborator

odow commented Mar 23, 2022

hence the reason we deploy with the pre-compiled Windows binaries prepared by the other solvers.

How does this work if you deploy GPL solvers like GLPK? Our static build of HiGHS includes the GCC runtime which is GPL, so you wouldn't be able to redistribute it unless your application was also GPL.

@jeffreydeankelly2
Copy link
Author

jeffreydeankelly2 commented Mar 23, 2022 via email

@jajhall jajhall added the enhancement New feature or request label Mar 25, 2022
@mmuetzel
Copy link
Contributor

Re licensing: IIUC, the GCC Runtime Library Exception allows linking the runtime (including statically) to non-GPLed code:
https://gcc.gnu.org/onlinedocs/libstdc++/manual/license.html

@mmuetzel
Copy link
Contributor

mmuetzel commented Mar 28, 2022

Do you know if there is a way to link to the *.dll.a similar to a *.lib file?

The .dll.a file extension is often used by mingw toolchains on Windows to indicate "import libraries". Import libraries are used on Windows when dynamically linking to a library. It might be possible to link to the .dll.a just like you would link to a .lib file. But you'd need to supply the "actual" dynamic library (.dll file) when running your program.

Actual static libraries often use the .lib or .a file extension with a mingw toolchain. They differ from static shared libraries by the fact, that the actual code of the library will be part of your program (licenses must be compatible!).

MSVC toolchains don't have established file extensions that differ between import libraries and static libraries. They use .lib by default for both. So, it depends on what you'd like to do: If you'd like to dynamically link highs, use the .dll.a files just like you would use the import libraries (potentially ending with .lib if they were compiled with MSVC) of other projects.
But keep in mind that mixing libraries compiled with MSVC and mingw might be problematic. It might work ok (e.g., if the interface is limited to POD types, malloc-free isn't used across library borders, and ...).

Additionally, that means that a static library (.lib) should not replace the existing import library (.dll.a). Both are used in different cases. (Maybe the title could be changed to reflect that?)

@jeffreydeankelly2
Copy link
Author

jeffreydeankelly2 commented Mar 28, 2022 via email

@mmuetzel
Copy link
Contributor

Thanks for clarifying.
Have you tested if you can link the (mingw) highs library with your (msvc) project? It might work. (But no guarantees it will.)

IIUC, your feature request is something like: "Distribute Windows binaries compiled with MSVC". Is that correct?

@jeffreydeankelly2
Copy link
Author

jeffreydeankelly2 commented Mar 28, 2022 via email

@odow
Copy link
Collaborator

odow commented Mar 28, 2022

The current binaries are compiled primarily for HiGHS.jl in Julia and made available for wider use. Notably, they aren't maintained or distributed by the official HiGHS team, and we don't have the ability to use MSVC in our compilation infrastructure (https://github.com/JuliaPackaging/Yggdrasil), so it's unlikely that this will happen from my side.

You have the ability to compile HiGHS yourself, otherwise, @jajhall might be in a position to provide commercial support.

@jeffreydeankelly2
Copy link
Author

This issue has been solved using the dll2lib.bat file which generates an import library *.LIB directly from the *.DLL.

The libhighs.lib was successfully created from the libhighs.dll and HiGHS has been interfaced to Intel oneAPI Fortran via Microsoft Studio 2019 with no issues.


Here is a website which hosts the MS DOS batch file to automatically generate the import library *.LIB using the Visual Studio ID dumpbin.exe, etc. utilities. This BAT file requires the path environment setup from a Microsoft Visual Studio IDE command prompt with administration priviliges.

https://rotadev.com/how-to-generate-an-import-library-lib-file-from-a-dll-dev/

REM Usage: dll2lib [32|64] some-file.dll
REM
REM Generates some-file.lib from some-file.dll, making an intermediate
REM some-file.def from the results of dumpbin /exports some-file.dll.
REM Currently must run without path on DLL.
REM (Fix by removing path when of lib_name for LIBRARY line below?)
REM
REM Requires 'dumpbin' and 'lib' in PATH - run from VS developer prompt.
REM
REM Script inspired by http://stackoverflow.com/questions/9946322/how-to-generate-an-import-library-lib-file-from-a-dll
SETLOCAL
if "%1"=="32" (set machine=x86) else (set machine=x64)
set dll_file=%2
set dll_file_no_ext=%dll_file:~0,-4%
set exports_file=%dll_file_no_ext%-exports.txt
set def_file=%dll_file_no_ext%.def
set lib_file=%dll_file_no_ext%.lib
set lib_name=%dll_file_no_ext%

dumpbin /exports %dll_file% > %exports_file%

echo LIBRARY %lib_name% > %def_file%
echo EXPORTS >> %def_file%
for /f "skip=19 tokens=1,4" %%A in (%exports_file%) do if NOT "%%B" == "" (echo %%B @%%A >> %def_file%)

lib /def:%def_file% /out:%lib_file% /machine:%machine%

REM Clean up temporary intermediate files
del %exports_file% %def_file% %dll_file_no_ext%.exp


@jajhall jajhall closed this as completed Aug 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants