Search code examples
c++ubuntumakefilecgal

makefile for CGAL (libcgal8)


I don't know why, but at each new version of CGAL, the procedure to compile completely changes. So, it's not even possible to recompile old piece of code (6 months old) because it doesn't work like that anymore.

I'm frankly very tired of redoing all the makefile of my projects that use CGAL each time. This time, for libcgal8, I don't find any simple substitute. Here's the makefile I was normally using:

ifndef CGAL_MAKEFILE
CGAL_MAKEFILE = /usr/local/cgal/share/cgal/cgal.mk
endif
include $(CGAL_MAKEFILE)

LIBPATH = \
          $(CGAL_LIBPATH)

LDFLAGS = \
          $(LONG_NAME_PROBLEM_LDFLAGS) \
          $(CGAL_LDFLAGS)

COMP=-frounding-math -fopenmp -std=c++0x -l json -L$(LIBPATH) $(LDFLAGS)
EXEC=../crender

all: main.o
    g++ -fPIC main.o $(EXEC) $(COMP)

main.o: main.cpp ../common/common.hpp
    g++ -c main.cpp $(COMP) -o main.o

So, what do I have to change to make it work again ? If possible, a solution that will survive to the future changes of CGAL.

If it can help, here's the kind of error that I get:

In function CGAL::Gmpq_rep::Gmpq_rep()':
main.cpp:(.text._ZN4CGAL8Gmpq_repC2Ev[_ZN4CGAL8Gmpq_repC5Ev]+0x14): undefined reference to
__gmpq_init'

And I get these kind of errors for other functions like "__gmpg_add", "__gmpq_sub" and "__gmpq_mul."

SOLUTION: You need to add "-lgmp" in the compilation instruction. It's sad that it's not done by default by the makefile provided by CGAL!


Solution

  • (Answered in the comments and in an Edit. See Question with no answers, but issue solved in the comments (or extended in chat) )

    The OP wrote:

    You need to add "-lgmp" in the compilation instruction. It's sad that it's not done by default by the makefile provided by CGAL!

    @sloriot Added:

    Since January 2009 (release 3.4), CGAL is using cmake as build system. Since then, all include/link compiler flags are provided through the cmake mechanism (CGALConfig.cmake).

    As mentioned above, now CGAL uses cmake as build system. While compiling CGAL example with cmake, I encountered similar problem. Solution is to add and link GMP library. Here is how its done for cmake: Cmake basic library linking problem