Search code examples
c++macoscgal

Run CGAL c++ program on OS X?


I want to be able to execute programs on my computer. I installed CGAL using Macports, I am not sure how to proceed next. Can anybody tell me how to execute the program, I am desperately trying to run the following program but don't know how to:

#include <iostream>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/convex_hull_2.h>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef K::Point_2 Point_2;
int main()
{
  Point_2 points[5] = { Point_2(0,0), Point_2(10,0), Point_2(10,10), Point_2(6,5), Point_2(4,1) };
  Point_2 result[5];
  Point_2 *ptr = CGAL::convex_hull_2( points, points+5, result );
  std::cout <<  ptr - result << " points on the convex hull:" << std::endl;
  for(int i = 0; i < ptr - result; i++){
    std::cout << result[i] << std::endl;
  }
  return 0;
}

Solution

  • CGAl gets installed on the directory :

    opt/local/include/cgal
    

    steps:

    1. Write your program into a text file and save excutable.cpp

    2. In the command line go to the directory of the executable( use cd command)

    3. then write the following commands

      cgal_create_CMakeLists -s executable //without .cpp!!

      cmake -DCGAL_DIR = opt/local/include/cgal

      make

    4. go to the folder where you saved executable.cpp and then click on the executable file(has a black square icon)

    5. and your done :)

    NOTE: only works if you installed using macports. if you installed using homebrew directories change,the procedure remains the same :)

    You also need command line tools installed.