using polymake in a C++ program

Questions and problems about using polymake go here.
soeren
Posts: 23
Joined: 12 Jul 2012, 22:25

using polymake in a C++ program

Postby soeren » 12 Jul 2012, 22:47

Hi,
I would like to use some of polymake's functionality in a C++ project, i.e. calling polymake functions from a C++ program. I've been using the interactive shell quite a bit, but I'm new to this topic.

As far as I understand the documentation writing a client is not what I intend. I've also found out that the next release will feature a callable library, which is in fact already usable. Is there any chance to get access to this library? Or is there any other way to use polymake from a C++ program?
I need this for a scientific project I work on, and it would be great to use pm here.

Best regards,
soeren

blorenz
Developer
Posts: 139
Joined: 10 Jan 2011, 17:21

Re: using polymake in a C++ program

Postby blorenz » 13 Jul 2012, 00:49

The callable library is working since version 2.10 and included in a default installation.

The documentation is here. There are also slides and an example program using the callable library in the material section from the first polymake workshop: http://www.polymake.org/doku.php/worksh ... terial#cal

In general you need a few lines of code to load the library (check the example), the syntax to use polymake objects then is identical to the C++ clients.

Benjamin

soeren
Posts: 23
Joined: 12 Jul 2012, 22:25

Re: using polymake in a C++ program

Postby soeren » 16 Jul 2012, 01:45

Thank you very much! I'm using Mac OS 10.7 and eventually I was able to install polymake(with additional packages from Fink).
However, I got some problems running the examples. When I try run one of the executables I get the following error messages:

Code: Select all

Undefined subroutine &Polymake::Ext::bootstrap called at /usr/local/share/polymake/perllib/Polymake/Main.pm line 25. BEGIN failed--compilation aborted at /usr/local/share/polymake/perllib/Polymake/Main.pm line 27. Compilation failed in require at /Users/Soeren/Documents/polymake-2.12/lib/callable/src/perl/Main.cc line 90. BEGIN failed--compilation aborted at /Users/Soeren/Documents/polymake-2.12/lib/callable/src/perl/Main.cc line 90. ERROR: could not initialize the perl interpreter Segmentation fault: 11
I was not able to figure out what went wrong. The polymake installation should be fine(at least no errors were shown).

This is what my Makefile looks like:

Code: Select all

PM_INC := $(shell polymake-config --includes) PM_CFLAGS := -fPIC -DPOLYMAKE_DEBUG=0 PM_LIBS := $(shell polymake-config --libs) PM_LDFLAGS := $(shell polymake-config --ldflags) CFLAGS += -march=native LDFLAGS += -lxml2 all: testprog smalltest smalltest.o: smalltest.cc g++-4 -mno-avx -o smalltest.o -c -I. ${PM_INC} ${PM_CFLAGS} ${CFLAGS} smalltest.cc smalltest: smalltest.o g++-4 -o smalltest smalltest.o ${PM_LDFLAGS} ${PM_LIBS} ${LDFLAGS} pm_object.o: pm_object.cc pm_object.h g++-4 -mno-avx -o pm_object.o -c -I. ${PM_INC} ${PM_CFLAGS} ${CFLAGS} pm_object.cc testprog.o: testprog.cc g++-4 -mno-avx -o testprog.o -c -I. ${CFLAGS} testprog.cc testprog: pm_object.o testprog.o g++-4 -o testprog testprog.o pm_object.o ${PM_LDFLAGS} ${PM_LIBS} ${LDFLAGS} clean: rm pm_object.o testprog.o testprog smalltest.o smalltest
Interestingly the -mno-avx flags were inevitable in order to compile the examples. This is kind of weird in my eyes, as my machine(Intel i7) and Mac OS should support AVX, but this might be a total different story.

Best regards,
Soeren

soeren
Posts: 23
Joined: 12 Jul 2012, 22:25

Re: using polymake in a C++ program

Postby soeren » 17 Jul 2012, 23:46

Today I tried polymake version 2.11 but got similar results. If someone has an idea for a fix or successfully used the callable lib on a mac, please let me know. I'm also still looking for the definition of the function 'bootstrap'(which is missing according to the error description), if someone could help me out I sure would be grateful.

best regards,
Sören

paffenholz
Developer
Posts: 212
Joined: 24 Dec 2010, 13:47

Re: using polymake in a C++ program

Postby paffenholz » 18 Jul 2012, 00:27

Both workshop examples do work on Mac OS 10.6, so I doubt that this is a Mac-specific problem. I don't have a any other idea how to solve this, though. I will also try on 10.7, but this might take some more days.

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

Re: using polymake in a C++ program

Postby gawrilow » 18 Jul 2012, 10:52

The bootstrap functions are produced automatically by the perl extension converter xsubpp, therefore you can't find them in the source code. The one you are missing stems from the source file lib/core/src/perl/Ext.xs, which is first converted to an intermediate file Ext.c (located in the build directory build.darwin.ARCH/perlx-VERSION-PERLARCH). Its C name is boot_Polymake_Ext, and it is bound to the perl name Polymake::Ext::bootstrap in a function xs_init, which is too automatically generated in the file Bootstrap.h in the same build directory. The function xs_init is in its turn called from the constructor of polymake::Main object (indirectly via perl interpreter method perl_parse), you can find this in lib/callable/src/perl/Main.cc

If you are going to investigate this issue in depth, you can start with setting breakpoints on the line in Main constructor where perl_parse is called as well as on the function xs_init and then watch whether both are in fact reached and executed properly.

paffenholz
Developer
Posts: 212
Joined: 24 Dec 2010, 13:47

Re: using polymake in a C++ program

Postby paffenholz » 16 Oct 2012, 11:26

This is a fink problem (sorry, below I only tried with two versions not depending on fink). fink's xsubpp terminates with

Code: Select all

zsh: /sw64/lib/perl5/ExtUtils/xsubpp: bad interpreter: perl: no such file or directory
The unofficial fix for this to replace the first line of xsubpp with

Code: Select all

#!/usr/bin/perl

(i.e. add a /usr/bin/). Then delete the contents of build.darwin.ARCH/perlx-VERSION-PERLARCH in your polymake installation, and do make, make install again.

paffenholz
Developer
Posts: 212
Joined: 24 Dec 2010, 13:47

Re: using polymake in a C++ program

Postby paffenholz » 17 Oct 2012, 15:35

The bug has been fixed in fink, but observe this before issuing fink selfupdate.

soeren
Posts: 23
Joined: 12 Jul 2012, 22:25

Re: using polymake in a C++ program

Postby soeren » 07 Dec 2012, 22:40

I tried this again today as you described. I'm now having problems to build polymake. Executing "./configure" gives me the error:

Code: Select all

WARNING: perl module Term::ReadLine::Gnu required for polymake not found on your machine. Please be sure to install it prior to starting to use polymake. If you have installed them in a non-standard location please add the path to the environment variable PERL5LIB
Fink says the term-readline-gnu-pm5123 is installed, and I did not installed anything to a non-standard location. I tried to fix this by changing the PERL5LIB, but it didn't work. In fact, I'm not sure what file exactly the configure script is looking for. Is it the /sw/lib/perl5-core/5.12.3/Term/ReadLine.pm or the /sw/lib/libreadline.6.2.dylib ? I added both paths to the PERL5LIB and the error did not go away.

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

Re: using polymake in a C++ program

Postby gawrilow » 08 Dec 2012, 00:19

...
Fink says the term-readline-gnu-pm5123 is installed, and I did not installed anything to a non-standard location. I tried to fix this by changing the PERL5LIB, but it didn't work. In fact, I'm not sure what file exactly the configure script is looking for. Is it the /sw/lib/perl5-core/5.12.3/Term/ReadLine.pm or the /sw/lib/libreadline.6.2.dylib ? I added both paths to the PERL5LIB and the error did not go away.
The missing file is .../Term/ReadLine/Gnu.pm . perl always converts package names into nested directories. PERL5LIB should point to the common directory of all perl packages you are going to use, above the platform name and version. In your case it would be simply /sw/lib/perl5-core . libreadline.6.2.dylib is by the way the (compiled) readline library itself, perl can't use it directly, but only via wrapper packages like Term::ReadLine::Gnu.


Return to “Helpdesk”