Page 1 of 2
using polymake in a C++ program
Posted: 12 Jul 2012, 22:47
by soeren
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
Re: using polymake in a C++ program
Posted: 13 Jul 2012, 00:49
by blorenz
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
Re: using polymake in a C++ program
Posted: 16 Jul 2012, 01:45
by soeren
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
Re: using polymake in a C++ program
Posted: 17 Jul 2012, 23:46
by soeren
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
Re: using polymake in a C++ program
Posted: 18 Jul 2012, 00:27
by paffenholz
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.
Re: using polymake in a C++ program
Posted: 18 Jul 2012, 10:52
by gawrilow
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.
Re: using polymake in a C++ program
Posted: 16 Oct 2012, 11:26
by paffenholz
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
(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.
Re: using polymake in a C++ program
Posted: 17 Oct 2012, 15:35
by paffenholz
The bug has been fixed in fink, but observe
this before issuing fink selfupdate.
Re: using polymake in a C++ program
Posted: 07 Dec 2012, 22:40
by soeren
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.
Re: using polymake in a C++ program
Posted: 08 Dec 2012, 00:19
by gawrilow
...
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.