1

I'm starting to work with cgal and I have just downloaded some sample code to start practicing. The problem is that when I try to compile the code, it returns:

ConvexHull.cpp:275:40: error: expected expression
sort(points.begin(), points.end(), [p] (Point_2 a, Point_2 b) -> int {
                                  ^
1 error generated.
make[2]: *** [CMakeFiles/exec.e.dir/ConvexHull.cpp.o] Error 1
make[1]: *** [CMakeFiles/exec.e.dir/all] Error 2
make: *** [all] Error 2

When I take a look at the code, everything seems ok:

Point_2 p = *(polygon.bottom_vertex());

sort(points.begin(), points.end(), [p] (Point_2 a, Point_2 b) -> int {
    Vector_2 v1(a, p);
    Vector_2 v2(b, p);
    
    return v1.direction() <= v2.direction();
});

Is this really wrong ? Am I using the wrong compiler (It's using by default Clang 3.1.0) ? Did I miss anything ?

Any help is greatly appreciated

By the way: I'm using OSX Lion to develop, and the only thing I've installed is cgal(using homebrew) and its dependencies. To compile I run:

cd path/to/folder
cgal_create_CMakeLists -c Qt4:Core:GMP:MPFR:Boost -s exec.e
cmake -DCGAL_DIR=$HOME/CGAL-4.2 -DCMAKE_BUILD_TYPE=Debug
make

EDIT

I managed to install gcc-4.8 and g++-4.8 using homebrew. Than I ran the cmake command like this:

cmake -DCGAL_DIR=$HOME/CGAL-4.2 -DCMAKE_CXX_COMPILER=g++-4.8 -DCMAKE_CC_COMPILER=gcc-4.8

Didn't even need to specify the c++11 flag. It generated the executable file, but when I run it using ./exec.e it segfaults Segmentation fault: 11. I am very frustrated at how hard this is turning out to be.

EDIT 2

I gave up using the MacOS. I was able to easily compile and run every required library and CGALon a linux using GCC-4.7.

5
  • 4
    Make sure you're using -std=c++11. Commented Jun 21, 2013 at 5:29
  • 2
    I think you have to use -std=c++11 option when compiling your code. Commented Jun 21, 2013 at 5:30
  • Hi @chris and @Nawaz. Thank you for your comments. Ive tried using the methods described in [here](http://pageant.ghulbus.eu/?p=664) but it still throws me the same error. How would you guys use -std=c+11` ? Just add this flag to the Makefile ? Commented Jun 21, 2013 at 5:52
  • Yeah, wherever your build command is, it needs to go in there and replace any of the related options for older versions. Commented Jun 21, 2013 at 5:56
  • Where have you downloaded that piece of code? I thought that CGAL examples were still using exclusively C++03. Commented Jun 24, 2013 at 12:29

1 Answer 1

3

The code example that you showed has a C++11 language feature called lambda expressions. Most compiler do not run in C++11 mode by default. To explicitly let them do so, put inside your CMakeLists.txt

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

and regenerate, rebuild and rerun everything to get your program to work correctly.

Sign up to request clarification or add additional context in comments.

4 Comments

There is currently a feature request targeted for CMake 2.8.12 to introduce a compiler-agnostic way of enabling C++11 support.
@ComicSansMS that's pretty nice!
I am convinced you are correct in your answer, but believe it or not the Clang compiler segfaulted when I added the flag. I am marking your answer as correct, and I'll search for another compiler option
@Luke the Clang 3.1 docs say std=c++11, if you happen to use an older version, you could try std=c++0x (also for gcc < 4.7).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.