CGAL的安装与环境配置

系统环境:Ubuntu-14.04


1.安装g++

$ sudo apt-get install g++


2. 安装boost

下载boost源文件【官网】

$tar -zxvf boost_1_58_0.tar.gz

$ cd boost_58_0

$ ./boostrap.sh

$ ./b2 install


3. 安装cmake

下载cmake源文件【官网】

$tar -zxvf cmake-3.3.2.tar.gz

$ cd cmake-3.3.2

$ ./bootstrap

$ make

$ make install


4.安装相关依赖库

$sudo apt-get install libgmp-dev libmpfr-dev

$sudo apt-get install libgmp-dev


5.安装CGAL

下载CGAL源文件【官网】

$ tar -zxvf CGAL_4.6.3.tar.gz

$ cd CGAL_4.6.3

$ cmake .

$ make

$ sudo make install


:如果报错OSError: libCGAL.so.11: cannot open shared object file: No such file or directory,解决方法:添加libCGAL.so路径,如:export LD_LIBRARY_PATH=/usr/local/lib; 或者在/etc/profiles文件中添加。


eg.

#include 
#include 
#include 
#include 
#include 
#include 


typedef CGAL::Simple_cartesian K;
typedef K::Point_2 Point;
typedef CGAL::Polygon_2 Polygon_2;
typedef CGAL::Polygon_with_holes_2 Polygon_with_holes_2;
using std::cout; using std::endl;


int main(){
  Point points[] = { Point(0,0), Point(2,0), Point(2,1), Point(0,1)};
  // Point points2[] = { Point(0.5,0.5), Point(1.5,0.5), Point(1.5,1.5), Point(0.5,1.5)};
  Point points2[] = { Point(0,0), Point(3,0), Point(3,2), Point(1,0.5)};
  Polygon_2 poly1(points, points+4);
  Polygon_2 poly2(points2, points2+4);
  //CGAL::General_polygon_with_holes_2 poly3;
  std::list polyI;

  double p1_area = poly1.area();

  double p2_area = poly2.area();

  CGAL::intersection(poly1, poly2, std::back_inserter(polyI));

  double totalArea = 0;
  typedef std::list::iterator LIT;
  for(LIT lit = polyI.begin(); lit!=polyI.end(); lit++){
    totalArea+=lit->outer_boundary().area();
  }
  cout << "poly1Area::" << p1_area <

编译命令:g++ -o poly.o polyOverlab2.cpp -L/usr/local/lib/ -lCGAL -lCGAL_Core -lgmp -lmpfr -lboost_system -lboost_filesystem -lboost_regex -lboost_thread

测试:./poly



你可能感兴趣的:(Environment,Configuration)