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

Postby Tryer » 28 Feb 2022, 18:23

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:

Image

and also attached as a .jpg with this message.
polymake_error.jpg
(167.96 KiB) Not downloaded yet
Any help is appreciated. Thanks.

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

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

Postby gawrilow » 01 Mar 2022, 00:37

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

Postby Tryer » 01 Mar 2022, 04:18

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.

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

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

Postby gawrilow » 01 Mar 2022, 10:36

You should add the polymake callable library and all relevant link flags to the link command. With your makefile, this should help:

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

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

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

Postby joswig » 01 Mar 2022, 10:38

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

Postby Tryer » 01 Mar 2022, 14:09

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

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

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

Postby gawrilow » 01 Mar 2022, 19:30

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

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

Please create such a link manually.

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

Postby Tryer » 02 Mar 2022, 00:28

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

Postby Tryer » 02 Mar 2022, 02:50

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

ninja -C build/Opt all ninja: Entering directory `build/Opt' [1/1] GENERATE /mnt/c/Users/Downloads/polymake-4.6/build/targets.ninja [38/562] RECONFIGURE /mnt/c/Users/Downloads/polymake-4.6/build/config.ninja checking C++ compiler ... ok (g++ is GCC 9.3.0) checking C++ library ... ok (GNU libstdc++ 20200808, C++ 201402) determining architecture ... ok (x86_64) determining compiler flags ... ok CFLAGS= -march=native CXXFLAGS= -std=c++14 -march=native -ftemplate-depth-200 -fno-strict-aliasing -fopenmp -Wshadow -Wlogical-op -Wconversion -Wzero-as-null-pointer-constant -Wno-parentheses -Wno-error=unused-function -Wno-stringop-overflow LDFLAGS= -fuse-ld=gold -fopenmp checking gmp installation ... ok checking mpfr installation ... ok checking boost installation ... ok checking perl module XML::SAX ... failed WARNING: perl module XML::SAX 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. checking perl module Term::ReadKey ... ok checking perl module Term::ReadLine ... ok checking perl module JSON ... ok checking shared perl library ... ok Configuring bundled extensions: bundled extension bliss ... failed bundled extension cdd ... ok (bundled) bundled extension flint ... ok (ok (2.5.2 @ system)) bundled extension java ... ok (JNI headers at /usr/lib/jvm/java-11-openjdk-amd64/include) bundled extension javaview ... failed bundled extension jreality ... ok (with bundled JOGL) bundled extension libnormaliz ... ok (bundled) bundled extension lrs ... ok (bundled) bundled extension nauty ... ok (source: bundled) bundled extension ppl ... failed bundled extension scip ... failed bundled extension singular ... failed bundled extension soplex ... failed bundled extension sympol ... ok (bundled) bundled extension atint ... ok * If you want to change the configuration of bundled extensions please see build/bundled.log and try configure --help. * Configuration successful. * You can run 'ninja -C build/Opt install' now to build and install polymake. WARNING: Please install/check the following perl modules prior to starting polymake: XML::SAX [562/562] GENERATE /mnt/c/Users/Downloads/polymake-4.6/build/targets.ninja [703/988] COMPILE /mnt/c/Users/Downloads/polymake-4.6/build/Opt/staticlib/lrsgmp/lrslib.o /mnt/c/Users/Downloads/polymake-4.6/bundled/lrs/external/lrs/lrslib.c: In function ‘lrs_read_dic_gmp’: /mnt/c/Users/Downloads/polymake-4.6/bundled/lrs/external/lrs/lrslib.c:1397:34: warning: ‘ ’ directive writing 1 byte into a region of size between 0 and 99 [-Wformat-overflow=] 1397 | sprintf(mess,"*%s %ld",name, Q->frequency); | ^ /mnt/c/Users/Downloads/polymake-4.6/bundled/lrs/external/lrs/lrslib.c:1397:30: note: directive argument in the range [1, 9223372036854775807] 1397 | sprintf(mess,"*%s %ld",name, Q->frequency); | ^~~~~~~~~ In file included from /usr/include/stdio.h:867, from /mnt/c/Users/Downloads/polymake-4.6/bundled/lrs/external/lrs/lrslib.c:26: /usr/include/x86_64-linux-gnu/bits/stdio2.h:36:10: note: ‘__builtin___sprintf_chk’ output between 4 and 121 bytes into a destination of size 100 36 | return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 37 | __bos (__s), __fmt, __va_arg_pack ()); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /mnt/c/Users/Downloads/polymake-4.6/bundled/lrs/external/lrs/lrslib.c:1424:32: warning: ‘ ’ directive writing 1 byte into a region of size between 0 and 99 [-Wformat-overflow=] 1424 | sprintf(mess,"*%s %ld",name, dict_limit); | ^ /mnt/c/Users/Downloads/polymake-4.6/bundled/lrs/external/lrs/lrslib.c:1424:28: note: using the range [-9223372036854775808, 9223372036854775807] for directive argument 1424 | sprintf(mess,"*%s %ld",name, dict_limit); | ^~~~~~~~~ In file included from /usr/include/stdio.h:867, from /mnt/c/Users/Downloads/polymake-4.6/bundled/lrs/external/lrs/lrslib.c:26: /usr/include/x86_64-linux-gnu/bits/stdio2.h:36:10: note: ‘__builtin___sprintf_chk’ output between 4 and 122 bytes into a destination of size 100 36 | return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 37 | __bos (__s), __fmt, __va_arg_pack ()); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /mnt/c/Users/Downloads/polymake-4.6/bundled/lrs/external/lrs/lrslib.c:1513:31: warning: ‘ ’ directive writing 2 bytes into a region of size between 1 and 100 [-Wformat-overflow=] 1513 | sprintf (mess, "%s %ld %ld", name, redundstart, redundend); | ^~ In file included from /usr/include/stdio.h:867, from /mnt/c/Users/Downloads/polymake-4.6/bundled/lrs/external/lrs/lrslib.c:26: /usr/include/x86_64-linux-gnu/bits/stdio2.h:36:10: note: ‘__builtin___sprintf_chk’ output between 6 and 143 bytes into a destination of size 100 36 | return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 37 | __bos (__s), __fmt, __va_arg_pack ()); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [714/988] COMPILE /mnt/c/Users/Downloads/polymake-4.6/build/Opt/staticlib/cddgmp/cddlp.o /mnt/c/Users/Downloads/polymake-4.6/bundled/cdd/external/cdd/lib-src-gmp/cddlp.c: In function ‘dd_RedundantRowsViaShooting’: /mnt/c/Users/Downloads/polymake-4.6/bundled/cdd/external/cdd/lib-src-gmp/cddlp.c:2954:28: warning: too many arguments for format [-Wformat-extra-args] 2954 | if (localdebug) printf("No interior-point is found and thus the standard LP technique will be used.\n", ired); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [715/988] COMPILE /mnt/c/Users/Downloads/polymake-4.6/build/Opt/staticlib/cddgmp/cddlp_f.o /mnt/c/Users/Downloads/polymake-4.6/bundled/cdd/external/cdd/lib-src-gmp/cddlp_f.c: In function ‘ddf_RedundantRowsViaShooting’: /mnt/c/Users/Downloads/polymake-4.6/bundled/cdd/external/cdd/lib-src-gmp/cddlp_f.c:2955:28: warning: too many arguments for format [-Wformat-extra-args] 2955 | redset=ddf_RedundantRows(M, error); | ^~~~~~~~~~~~ [944/988] BUILD /mnt/c/Users/Downloads/polymake-4.6/build/Opt/jars/polymake_java.jar Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: Some input files use unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. [988/988] BUILD /mnt/c/Users/Downloads/polymake-4.6/build/Opt/jars/polymake_jreality.jar Using Java version 11. Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: Some input files use unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. Note: /mnt/c/Users/Downloads/polymake-4.6/bundled/jreality/external/jreality/src-tool/de/jreality/toolsystem/virtual/VirtualExtractPositive.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: Some input files use unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. Note: /mnt/c/Users/Downloads/polymake-4.6/bundled/jreality/external/jreality/src-backends-share/de/jreality/backends/label/LabelUtility.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. warning: [options] bootstrap class path not set in conjunction with -source 7 Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: Some input files use unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 1 warning Note: /mnt/c/Users/Downloads/polymake-4.6/bundled/jreality/external/jreality/src-proxies/de/jreality/scene/proxy/smrj/SMRJMirrorFactory.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: Some input files use unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: Some input files use unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: /mnt/c/Users/Downloads/polymake-4.6/bundled/jreality/external/jreality/src-ui/de/jreality/geometry/AbstractGeometryFactoryCustomizer.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: Some input files use unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details.

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

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

Postby gawrilow » 02 Mar 2022, 09:26

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.


Return to “Helpdesk”