Static library/Linking Polymake C++ code for windows machine

Questions and problems about using polymake go here.
Tryer
Posts: 13
Joined: 28 Feb 2022, 17:53

Static library/Linking Polymake C++ code for windows machine

Postby Tryer » 06 Mar 2022, 04:41

Hello,

This is more a C++ linking/compiling question rather than a polymake question.

This line from polymake's documentation seems to suggest that a "unix emulation" is needed on Windows https://polymake.org/doku.php/install/install:
polymake is not supported on any native Windows platform. You might try to get it running in a UNIX emulation like Cygwin, but you will be left to your own devices since we are not used to this setup.
I am hoping this only refers to running polymake as a stand alone program from the command line.

One of my collaborators is unable to install polymake because it is not possible for him to get access to a Linux or WSL machine. He works on a pure windows machine. I am able to work and develop C++ code using polymake headers since I have access to WSL and Linux.

I read the following line in the documentation https://polymake.org/doku.php/callable:
The polymake as a library must be initialized by creating an instance of class polymake::Main. This class is declared in the header polymake/Main.h . Special precaution prevents including this header in the polymake clients, it's designed exclusively for standalone programs.
Does this mean that there is no way I can do something on my computer (which has WSL or Linux installed) -- essentially create a static library file (.lib) of polymake specific code that my collaborator can link to on his pure Windows machine on his C++ IDE?

Thanks.

User avatar
gawrilow
Main Author
Posts: 425
Joined: 25 Dec 2010, 17:40

Re: Static library/Linking Polymake C++ code for windows machine

Postby gawrilow » 06 Mar 2022, 09:21

When you build polymake (and any other software) on a Linux system, the resulting binary will contain innumerable references to functions defined in C++ runtime environment and system libraries. You can use such a binary only on a system which has all the same libraries in compatible versions. A statically built executable will contain copies of relevant portions of system libraries, but still it will try to execute various syscalls, e.g. to allocate new memory or read some file. I would be surprised if a program statically built under WSL would work in a pure Windows environment, but I'm not an expert on Windows.

There is nothing specific to polymake::Main in this regard (the quote from the documentation is not related to your problem), but polymake does not support static linking. The reason is that it is based on perl shared library which loads tons of modules dynamically after the initial startup phase. In particular, all applications (polytope, tropical, topaz, etc.) are built as separate shared modules and loaded on demand.

Thus, the answer to your question is, unfortunately, No. Your collaborators should install WSL if they want to run any programs based on polymake callable library.
If all what you need from polymake is to do convex hull computations, you might consider standalone static libraries of cddlib or lrslib directly. They are not using any dynamic modules. Maybe ppl is also available in static fashion.

Tryer
Posts: 13
Joined: 28 Feb 2022, 17:53

Re: Static library/Linking Polymake C++ code for windows machine

Postby Tryer » 06 Mar 2022, 14:00

Thanks for the explanation.

In my application, I have to use another library only by static linking since the providers of that library (CPLEX) do not provide shared linking for linux. I went ahead trying to include polymake and was able to compile and link/build successfully. However, linking now provides a warning with regards to the other library:

/usr/bin/ld.gold: warning: /opt/ibm/ILOG/CPLEX_Studio1210/cplex/lib/x86-64_linux/static_pic/libcplex.a(ucnv_io.ao): section .rodata.str1.32 contains incorrectly aligned strings; the alignment of those strings won't be preserved
/usr/bin/ld.gold: warning: /opt/ibm/ILOG/CPLEX_Studio1210/cplex/lib/x86-64_linux/static_pic/libcplex.a(ucnv_bld.ao): section .rodata.str1.32 contains incorrectly aligned strings; the alignment of those strings won't be preserved

I doubt there is any easy fix to these issues now -- one library being linked statically, the other dynamically/shared (assuming that is the reason for this new warning).

I am able to confirm that this is a new warning I obtain from the other library that I did not obtain before so I cannot possibly raise this query with CPLEX folks.

Is there any easy way out of this?

Thanks.

User avatar
gawrilow
Main Author
Posts: 425
Joined: 25 Dec 2010, 17:40

Re: Static library/Linking Polymake C++ code for windows machine

Postby gawrilow » 06 Mar 2022, 18:10

As such it's not forbidden to mix statically and dynamically linked libraries in one executable. I don't think the warning should have dramatic consequences. Just go ahead.

User avatar
joswig
Main Author
Posts: 288
Joined: 24 Dec 2010, 11:10

Re: Static library/Linking Polymake C++ code for windows machine

Postby joswig » 06 Mar 2022, 20:37

One comment: to run polymake code on a pure Windows machine you could employ some live version of Linux, e.g., Ubuntu.

And a question: which computation do you want to do with CPLEX? polymake is capable of solving (mixed integer) linear programs exactly. Of course, CPLEX is much faster (as it uses float arithmetic, and, of course, it is optimized for solving large MILPs).

Tryer
Posts: 13
Joined: 28 Feb 2022, 17:53

Re: Static library/Linking Polymake C++ code for windows machine

Postby Tryer » 07 Mar 2022, 01:26

My usage of CPLEX is somewhat advanced -- I have to use some sort of repeated branch and cut with cut callbacks to solve large difficult integer programs. Efficiency is critical and in our experience CPLEX performs quite adequately in its correctness.

I will try the various ideas suggested and see which works for our case.

Thanks Gawrilow and Joswig for your help.


Return to “Helpdesk”