3
votes

I'm a newbie of CGAL and I'm using CGAL 4.7-4 on Ubuntu 16.04. I'm trying to compile and run a very simple .cpp. Here is the code:

#include <iostream>
#include <CGAL/Cartesian.h>

int main()
{
 int p=2;
 std::cout << "hello " << p << std::endl;
 return 0;
}

I added the line

#include <CGAL/Cartesian.h>

because I want to see how to compile with more libraries. Then I wrote this line on the terminal

g++ -lCGAL -lgmp prova.cpp

but I got this error:

/tmp/cc9DA7Ml.o: In function 'CGAL::Interval_nt::Test_runtime_rounding_modes::Test_runtime_rounding_modes()':

prova.cpp:(.text._ZN4CGAL11Interval_ntILb0EE27Test_runtime_rounding_modesC2Ev[_ZN4CGAL11Interval_ntILb0EE27Test_runtime_rounding_modesC5Ev]+0xd2): undefined reference to 'CGAL::assertion_fail(char const*, char const*, int, char const*)'

prova.cpp:(.text._ZN4CGAL11Interval_ntILb0EE27Test_runtime_rounding_modesC2Ev[_ZN4CGAL11Interval_ntILb0EE27Test_runtime_rounding_modesC5Ev]+0x180): undefined reference to 'CGAL::assertion_fail(char const*, char const*, int, char const*)'

/tmp/cc9DA7Ml.o: In function 'CGAL::Interval_nt::Test_runtime_rounding_modes::Test_runtime_rounding_modes()':

prova.cpp:(.text._ZN4CGAL11Interval_ntILb1EE27Test_runtime_rounding_modesC2Ev[_ZN4CGAL11Interval_ntILb1EE27Test_runtime_rounding_modesC5Ev]+0xd2): undefined reference to 'CGAL::assertion_fail(char const*, char const*, int, char const*)'

prova.cpp:(.text._ZN4CGAL11Interval_ntILb1EE27Test_runtime_rounding_modesC2Ev[_ZN4CGAL11Interval_ntILb1EE27Test_runtime_rounding_modesC5Ev]+0x180): undefined reference to 'CGAL::assertion_fail(char const*, char const*, int, char const*)'

collect2: error: ld returned 1 exit status

I got the same error even if I wrote anyone of these lines:

g++ -lCGAL -lmpfr -lgmp prova.cpp

g++ -I/opt/local/include -L/opt/local/lib -lCGAL -lgmp prova.cpp

g++ -I/opt/local/include -L/opt/local/lib/ -lCGAL -lgmp prova.cpp

g++ -I/usr/include -L/usr/bin -lCGAL -lgmp prova.cpp

g++ -I/usr/bin -L/usr/lib -lCGAL -lgmp prova.cpp

If I wrote

g++ -lCartesian.a -lCGAL -lgmp prova.cpp

or

g++ -lCartesian -lCGAL -lgmp prova.cpp

I got this error on the terminal

/usr/bin/ld: cannot find -lCartesian.a

collect2: error: ld returned 1 exit status

And at the end if I wrote

g++ -I/usr/include/CGAL -L/usr/include/CGAL -lCGAL -lgmp prova.cpp

I got a very long list of errors like these:

In file included from /usr/include/CGAL/gmpxx_coercion_traits.h:35:0,

             from /usr/include/CGAL/mpz_class.h:29,
             from /usr/include/CGAL/gmpxx.h:47,
             from /usr/include/CGAL/is_convertible.h:28,
             from /usr/include/CGAL/Rational_traits.h:31,
             from /usr/include/CGAL/number_type_basic.h:48,
             from /usr/include/CGAL/basic.h:44,
             from /usr/include/CGAL/Cartesian/Cartesian_base.h:28,
             from /usr/include/CGAL/Cartesian.h:28,
             from prova.cpp:2:

/usr/include/mpfr.h:181:3: error: ‘mp_limb_t’ does not name a type mp_limb_t *_mpfr_d;

/usr/include/mpfr.h:279:1: error: ‘__GMP_DECLSPEC’ does not name a type __MPFR_DECLSPEC __gmp_const char * mpfr_get_version _MPFR_PROTO ((void));

[...]

In file included from /usr/include/CGAL/mpz_class.h:29:0,

             from /usr/include/CGAL/gmpxx.h:47,
             from /usr/include/CGAL/is_convertible.h:28,
             from /usr/include/CGAL/Rational_traits.h:31,
             from /usr/include/CGAL/number_type_basic.h:48,
             from /usr/include/CGAL/basic.h:44,
             from /usr/include/CGAL/Cartesian/Cartesian_base.h:28,
             from /usr/include/CGAL/Cartesian.h:28,
             from prova.cpp:2:

/usr/include/CGAL/gmpxx_coercion_traits.h:43:3: error: ‘::__gmp_expr’ has not been declared

::__gmp_expr< T , U>,::__gmp_expr< T , U> >{

[...]

And the long list finishes like this:

In file included from /usr/include/CGAL/double.h:30:0,

             from /usr/include/CGAL/number_type_basic.h:60,
             from /usr/include/CGAL/basic.h:44,
             from /usr/include/CGAL/Cartesian/Cartesian_base.h:28,
             from /usr/include/CGAL/Cartesian.h:28,
             from prova.cpp:2:

/usr/include/CGAL/number_utils.h: In instantiation of ‘typename CGAL::Real_embeddable_traits::Is_finite::result_type CGAL::is_finite(const Real_embeddable&) [with Real_embeddable = double; typename CGAL::Real_embeddable_traits::Is_finite::result_type = CGAL::Null_tag]’:

/usr/include/CGAL/double.h:201:27: required from here

/usr/include/CGAL/number_utils.h:263:75: error: no match for call to ‘(CGAL::INTERN_RET::Real_embeddable_traits_base >::Is_finite {aka CGAL::Null_functor}) (const double&)’

return typename Real_embeddable_traits< Real_embeddable >::Is_finite()( x );

I've looked around on the web a lot and I've understand something is wrong with the linking part of the compilation (no problem with the core), but I really don't have any idea about the solution. Do you have any idea? Thanks in advance for helping.

2

2 Answers

6
votes
g++ prova.cpp -lCGAL

works... It seems it was just a matter of order.

0
votes

Simply, use C++ version 14.

If you are using Qt then change your C++ version by doing the following in the .pro file.

CONFIG += c++14