widgg
widgg

Reputation: 1428

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!

Upvotes: 3

Views: 2863

Answers (2)

Eliasz Łukasz
Eliasz Łukasz

Reputation: 548

This is my makefile for linux and mac os x (no using cmake):

CPP        := g++
OPCJE      := -W -Wall -pedantic -O0 -Wno-c++11-extensions
BIBLIOTEKI := -lboost_math_c99 -lboost_thread -lm -lCGAL -lmpfr -lgmp
PISZ := echo -e
UNAME_S := $(shell uname -s)

on Mac os X some library are different name (brew install)

ifeq ($(UNAME_S),Darwin)
 BIBLIOTEKI = -lboost_math_c99 -lboost_thread-mt -lm -lcgal -lmpfr -lgmp
 PISZ = echo
endif

all source SRC = $(wildcard *.cpp) OBJ = $(addsuffix .o, $(basename $(SRC)))

BIN_DIR  = ./bin
W_ZRODLA = $(wildcard *.cpp)
PROGRAMY = ${W_ZRODLA:%.cpp=$(BIN_DIR)/%}

$(BIN_DIR)/%: %.cpp
    @mkdir -p ./bin
    $(CPP) $(OPCJE) $< -o $@ $(BIBLIOTEKI)

wszystkie: $(PROGRAMY)
    @echo

clean:
    rm -f ./bin/*

mem: 01
    valgrind -v --tool=memcheck --leak-check=full ./01

Upvotes: 1

(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

Upvotes: 2

Related Questions