## Running into a compile error on example C++ code

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

### Running into a compile error on example C++ code

Hello,

I am trying to use polymake from within C/C++ code. To get started, I tried to compile and link the example provided on this presentation: http://polymake.org/lib/exe/fetch.php/cal_pres.pdf available on polymake website.

Unfortunately, I obtain a compile time error that namespace "polymake::perl" has no member "Object"

A screenshot of the error is pasted below:

and also attached as a .jpg with this message.
polymake_error.jpg
Any help is appreciated. Thanks.

gawrilow
Main Author
Posts: 405
Joined: 25 Dec 2010, 17:40

### Re: Running into a compile error on example C++ code

This is quite an old presentation, some things have been changed and/or renamed since then.
In case of this example, you should replace "polymake::perl::Object" with "BigObject" without namespace prefixes.

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

### Re: Running into a compile error on example C++ code

The immediate compile error does go away. I obtain a bunch of undefined references however. I try following the steps here:

https://www.polymake.org/doku.php/calla ... _a_program

Specifically, the relevant parts of my makefile are:

Code: Select all

PM_INC := $(shell polymake-config --includes) # CC Compiler Flags CCFLAGS=-m64 -fno-common -fPIC -fno-strict-aliasing -fexceptions -fopenmp -DVSCODE -DPOLYMAKE_DEBUG=0 CXXFLAGS=-m64 -fno-common -fPIC -fno-strict-aliasing -fexceptions -fopenmp -DVSCODE -DPOLYMAKE_DEBUG=0 # Link Libraries and Options LDLIBSOPTIONS= # Build Targets .build-conf:${BUILD_SUBPROJECTS} "${MAKE}" -f nbproject/Makefile-${CND_CONF}.mk ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/linux${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/linux: ${OBJECTFILES}${MKDIR} -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}${LINK.cc} -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/linux${OBJECTFILES} ${LDLIBSOPTIONS} -lm -lpthread -ldl${OBJECTDIR}/_ext/511e4115/Main.o: ../src/Main.cpp ${MKDIR} -p${OBJECTDIR}/_ext/511e4115 ${RM} "$@.d" $(COMPILE.cc) -g -DIL_STD -D_LINDEBUG -I../include -I.${PM_INC} -std=c++14 -MMD -MP -MF "$@.d" -o${OBJECTDIR}/_ext/511e4115/Main.o ../src/Main.cpp
The errors make gives are:

Code: Select all

make[1]: polymake-config: Command not found g++ -m64 -fno-common -fPIC -fno-strict-aliasing -fexceptions -fopenmp -DVSCODE -DPOLYMAKE_DEBUG=0 -o dist/Debug/GNU-Linux/linux build/Debug/GNU-Linux/_ext/511e4115/Main.o -lm -lpthread -ldl /usr/bin/ld: build/Debug/GNU-Linux/_ext/511e4115/Main.o: in function main': /mnt/c/Users/GoogleDrive/LinuxBox/polymake/.vscode/../src/Main.cpp:9: undefined reference to pm::perl::Main::Main(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
and many others of similar nature.

The line that gives this undefined reference is:

Code: Select all

Main pm;
I have tried to model my makefile based on a sample makefile available at http://polymake.org/lib/exe/fetch.php/callable.tbz also from polymake page: https://polymake.org/doku.php/callable

Could you please direct me to a makefile and code example that works with the current release? I have searched through the forums and the example I could find are also somewhat dated: viewtopic.php?f=9&t=192 for instance.

gawrilow
Main Author
Posts: 405
Joined: 25 Dec 2010, 17:40

### Re: Running into a compile error on example C++ code

LDLIBSOPTIONS := $(shell polymake-config --ldflags)$(shell polymake-config --libs)

joswig
Main Author
Posts: 269
Joined: 24 Dec 2010, 11:10

### Re: Running into a compile error on example C++ code

In addition to what Ewgenij said, you will need to make sure that the executable polymake-config is in your path.

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

### Re: Running into a compile error on example C++ code

Thank you gawrilow and joswig. I had to sudo apt install libpolymake-dev to get polymake-config to my path. It was not being recognized otherwise. I am able to compile and link and build the executable fine.

Now, as I am stepping through the code in a debugging session, I don't seem to be able to step over the line Main pm;

I get the error,

ERROR: polymake::Main - /usr/lib/polymake/shared is not a symlink

The code I am stepping through is the same code originally presented in the pdf file I liked to in my opening post. It is:

Code: Select all

#include <polymake/Main.h> #include <polymake/Matrix.h> #include <polymake/SparseMatrix.h> #include <polymake/Rational.h> using namespace polymake; int main(int argc, const char* argv[]) { try { const int dim = 4; Main pm; pm.set_application("polytope"); BigObject p("Polytope<Rational>"); p.take("VERTICES") << (ones_vector<Rational>() | 3*unit_matrix<Rational>(dim)); const Matrix<Rational> f = p.give("FACETS"); const Vector<Integer> h = p.give("H_STAR_VECTOR"); cout << "facets" << endl << f << endl << "h* " << h << endl; } catch (const std::exception& ex) { std::cerr << "ERROR: " << ex.what() << endl; return 1; } return 0; }
Could you please help? I don't know if it could be because I am running all of this on WSL on an otherwise Windows machine. I checked on both WSL as well as a pure linux machine -- /usr/lib/polymake/shared does not exist on either machines. The contents of the folder are lib, perlx and config.ninja

gawrilow
Main Author
Posts: 405
Joined: 25 Dec 2010, 17:40

### Re: Running into a compile error on example C++ code

It looks indeed like the package is wrongly composed, there should be a symlink

shared -> ../../share/polymake

The most probable reason for the sad fact that nobody reported this error before is that the rare brave hearts who dare to develop own C++ code using polymake are installing it from the sources...

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

### Re: Running into a compile error on example C++ code

Creation of the symlink eliminated that error. Now, there is a new error on that very line:

Code: Select all

Can't locate Polymake/Main.pm in @INC (you may need to install the Polymake::Main module) (@INC contains: /usr/share/perllib /usr/lib/polymake/perlx/5.30.0/x86_64-linux-gnu-thread-multi /usr/lib/polymake/perlx/5.30.0 /usr/lib/polymake/perlx /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.30.0 /usr/local/share/perl/5.30.0 /usr/lib/x86_64-linux-gnu/perl5/5.30 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.30 /usr/share/perl/5.30 /usr/local/lib/site_perl) at -e line 9. BEGIN failed--compilation aborted at -e line 9.
Let me try to completely delete my current polymake installation which was done using sudo apt install and try to build it from source to see if that removes the errors.

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

### Re: Running into a compile error on example C++ code

Indeed building from source code did the trick. The symlink was not created by default. I had to do the following manually:

:/usr/lib/polymake\$ sudo ln -s ../../share/polymake/ shared

The c++ code compiled and ran fine. I obtained the following output:

Code: Select all

polymake: used package cdd cddlib Implementation of the double description method of Motzkin et al. Copyright by Komei Fukuda. http://www-oldurls.inf.ethz.ch/personal/fukudak/cdd_home/ polymake: used package libnormaliz [[wiki:external_software#Normaliz]] is a tool for computations in affine monoids, vector configurations, lattice polytopes, and rational cones. Copyright by Winfried Bruns, Bogdan Ichim, Christof Soeger. http://www.math.uos.de/normaliz/ facets 3 -1 -1 -1 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 h* 1 16 10 0
If it will help the developers, I state below the warnings I received from the building from source process:

Code: Select all

gawrilow
Main Author
Posts: 405
Joined: 25 Dec 2010, 17:40

### Re: Running into a compile error on example C++ code

Thanks for the detailed report! The warnings are harmless, they come from third-party components bundled with polymake.

However, I can't imagine the reason why this /shared symlink is missing. We are constantly monitoring the health of the callable library in our CI pipeline, which includes building and running small test programs like yours. Admittedly, we are doing this in a native Linux environment, not under Windows. But in your case other symlinks, pointing to shared libraries, are present, and they are all created by exactly the same installation script in one go.

It would be great if you could sacrifice a bit of your free time for a deeper investigation of this problem. Then I'd mail you detailed instructions.