用CGAL编译一个简单的测试 [英] compile a simple test with CGAL

查看:285
本文介绍了用CGAL编译一个简单的测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在mac系统上安装了brew的CGAL。现在我很兴奋,尝试一个简单和最小的例子。我可以用g ++编译这个示例文件:

  gcc namefile.cpp -lCGAL -I / usr / local / include / CGAL 

我遇到了很多错误...(太多,无法粘贴到这里我认为)



作为示例文件我使用

 文件:examples / Arrangement_on_surface_2 / sweep_line.cpp 



#include< CGAL / Cartesian。 h。
#include< CGAL / MP_Float.h>
#include< CGAL / Quotient.h>
#include< CGAL / Arr_segment_traits_2.h>
#include< CGAL / Sweep_line_2_algorithms.h>
#include< list>

typedef CGAL :: Quotient< CGAL :: MP_Float> NT;
typedef CGAL :: Cartesian< NT>核心;
typedef Kernel :: Point_2 Point_2;
typedef CGAL :: Arr_segment_traits_2< Kernel> Traits_2;
typedef Traits_2 :: Curve_2 Segment_2;

int main()
{
//构造输入段。
Segment_2 segments [] = {Segment_2(Point_2(1,5),Point_2(8,5)),
Segment_2(Point_2(1,1),Point_2(8,8)),
Segment_2(Point_2(3,1),Point_2(3,8)),
Segment_2(Point_2(8,5),Point_2(8,8))};

//计算所有交点。
std :: list< Point_2> pts;

CGAL :: compute_intersection_points(segments,segments + 4,
std :: back_inserter(pts));

//打印结果。
std :: cout<< Found< pts.size()<< 交叉点:< std :: endl;
std :: copy(pts.begin(),pts.end(),
std :: ostream_iterator< Point_2>(std :: cout,\\\
));

//计算由输入段引起的不相交的子段。
std :: list< Segment_2> sub_segs;

CGAL :: compute_subcurves(segments,segments + 4,std :: back_inserter(sub_segs));

std :: cout<< Found< sub_segs.size()
<< 内部不相交的子段。 << std :: endl;

CGAL_assertion(CGAL :: do_curves_intersect(segments,segments + 4));

return 0;
}



EDIT:



 >>> g ++ --version 
i686-apple-darwin11-llvm-g ++ - 4.2(GCC)4.2.1(基于Apple Inc.构建5658)(LLVM构建2336.11.00)
版权所有免费软件基金会,
这是免费软件;请参阅复制条件的来源。有NO

>>>> g ++ sweep_line.cpp
在/usr/local/include/CGAL/Bbox_2.h:31中包含的文件中,
来自/usr/local/include/CGAL/basic_classes.h:31,
来自/usr/local/include/CGAL/Cartesian/Cartesian_base.h:29,
来自/usr/local/include/CGAL/Cartesian.h:28,
来自sweep_line.cpp:4:
/usr/local/include/CGAL/array.h:81:error:expected'...'之前的嵌套名称说明符标记
/usr/local/include/CGAL/array.h :81:error:expected'>'before'...'token
/usr/local/include/CGAL/array.h:83:error:模板参数2无效
/ usr / '$'之前的'local'/ local / include / CGAL / array.h:84:error:expected','或'...'
/usr/local/include/CGAL/array.h: int CGAL :: make_array(const T& int)':
/usr/local/include/CGAL/array.h:86:error:模板参数2无效
/ usr / local / include /CGAL/array.h:86:error:无效类型在声明之前'='token
/usr/local/include/CGAL/array.h:86:error:'args'未在此范围中声明
/usr/local/include/CGAL/array.h:86:error:expected`}'before'...'token
/usr/local/include/CGAL/array.h:86 :error:expected`}'before'...'token
/usr/local/include/CGAL/array.h:86:error:expected','或';'before'...'
/usr/local/include/CGAL/array.h:在全局范围:
/usr/local/include/CGAL/array.h:87:error:expected'返回'前的未限定ID
/usr/local/include/CGAL/array.h:88:error:预期声明前'}'token
保修;甚至不适用于适销性或特定用途的适用性。



>>> g ++ sweep_line.cpp -lCGAL -I / usr / local / include / CGAL
在/ usr / local中包含的文件/include/CGAL/gmpxx_coercion_traits.h:35,
来自/usr/local/include/CGAL/mpz_class.h:29,
来自/usr/local/include/CGAL/gmpxx.h:47 ,
从/usr/local/include/CGAL/is_convertible.h:28,
从/usr/local/include/CGAL/Rational_traits.h:31,
从/ usr / local /include/CGAL/number_type_basic.h:65,
来自/usr/local/include/CGAL/basic.h:36,
来自/usr/local/include/CGAL/Cartesian/Cartesian_base.h :28,
来自/usr/local/include/CGAL/Cartesian.h:28,
来自sweep_line.cpp:4:
/usr/local/include/mpfr.h:181 :error:expected';'before'*'token
/usr/local/include/mpfr.h:279:error:expected之前的构造函数,析构函数或类型转换
/ usr / local / include / mpfr.h:280:error:expected之前的构造函数,析构函数或类型转换
/usr/local/include/mpfr.h:281:error:expected constructor,destructor或type转换'int'之前
/usr/local/include/mpfr.h:282:错误:预期的构造函数,析构函数或类型转换'int'之前
/usr/local/include/mpfr.h :283:error:'int'之前的构造函数,析构函数或类型转换
/usr/local/include/mpfr.h:284:error:在const之前的构造函数,析构函数或类型转换
/usr/local/include/mpfr.h:286:error:'__GMP_DECLSPEC'没有命名类型
/usr/local/include/mpfr.h:287:error:expected构造函数,析构函数或类型转换'int'之前
/usr/local/include/mpfr.h:288:错误:'__GMP_DECLSPEC'不命名类型
/usr/local/include/mpfr.h:289:错误:'__GMP_DECLSPEC'未命名类型
/usr/local/include/mpfr.h:290:错误:'__GMP_DECLSPEC'未命名类型
/ usr / local / include / mpfr。 h:291:error:'int'之前的构造函数,析构函数或类型转换
/usr/local/include/mpfr.h:292:错误:'__GMP_DECLSPEC'未命名类型
/ usr / local / include / mpfr.h:293:错误:'__GMP_DECLSPEC'未命名类型
/usr/local/include/mpfr.h:295:error:expected构造函数,析构函数或类型转换'void'
/usr/local/include/mpfr.h:296:error:'__GMP_DECLSPEC'没有命名类型
/usr/local/include/mpfr.h:297:error:expected构造函数,析构函数或类型转换之前'const'
/usr/local/include/mpfr.h:300:error:expected之前的构造函数,析构函数或类型转换
/ usr / local /include/mpfr.h:301:error:expected之前的构造函数,析构函数或类型转换
/usr/local/include/mpfr.h:302:error:expected构造函数,析构函数或类型转换before'void'
/usr/local/include/mpfr.h:303:error:'void'之前的构造函数,析构函数或类型转换
/usr/local/include/mpfr.h: 304:错误:'void'之前的构造函数,析构函数或类型转换


解决方案

您有两种方法:


  1. 允许C ++ 11通过向编译器添加相应的标志( --std = c ++ 11 - std = c ++ 0x )。

  2. 定义 CGAL_CFG_NO_CPP0X_ARRAY CGAL_CFG_NO_TR1_ARRAY CGAL_CFG_NO_VARIADIC_TEMPLATES 。注意:在这种情况下,您需要 boost / array.hpp 头。


I have just installed CGAL with brew on a mac system. Now I'm exciting to try it with a simple and minimal example. Ho can I compile it with g++?

I want to compile this sample file with:

gcc namefile.cpp -lCGAL -I/usr/local/include/CGAL

and I get a lot of errors... (too many to paste it here I think)

as example file I'm using

File: examples/Arrangement_on_surface_2/sweep_line.cpp



#include <CGAL/Cartesian.h>
#include <CGAL/MP_Float.h>
#include <CGAL/Quotient.h>
#include <CGAL/Arr_segment_traits_2.h>
#include <CGAL/Sweep_line_2_algorithms.h>
#include <list>

typedef CGAL::Quotient<CGAL::MP_Float>                  NT;
typedef CGAL::Cartesian<NT>                             Kernel;
typedef Kernel::Point_2                                 Point_2;
typedef CGAL::Arr_segment_traits_2<Kernel>              Traits_2;
typedef Traits_2::Curve_2                               Segment_2;

int main()
{
  // Construct the input segments.
  Segment_2 segments[] = {Segment_2 (Point_2 (1, 5), Point_2 (8, 5)),
                          Segment_2 (Point_2 (1, 1), Point_2 (8, 8)),
                          Segment_2 (Point_2 (3, 1), Point_2 (3, 8)),
                          Segment_2 (Point_2 (8, 5), Point_2 (8, 8))};

  // Compute all intersection points.
  std::list<Point_2>     pts;

  CGAL::compute_intersection_points (segments, segments + 4,
                                     std::back_inserter (pts));

  // Print the result.
  std::cout << "Found " << pts.size() << " intersection points: " << std::endl; 
  std::copy (pts.begin(), pts.end(),
             std::ostream_iterator<Point_2>(std::cout, "\n"));

  // Compute the non-intersecting sub-segments induced by the input segments.
  std::list<Segment_2>   sub_segs;

  CGAL::compute_subcurves(segments, segments + 4, std::back_inserter(sub_segs));

  std::cout << "Found " << sub_segs.size()
            << " interior-disjoint sub-segments." << std::endl;

  CGAL_assertion (CGAL::do_curves_intersect (segments, segments + 4));

  return 0;
}

EDIT:

>>> g++ --version
i686-apple-darwin11-llvm-g++-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO

>>> g++ sweep_line.cpp
In file included from /usr/local/include/CGAL/Bbox_2.h:31,
                 from /usr/local/include/CGAL/basic_classes.h:31,
                 from /usr/local/include/CGAL/Cartesian/Cartesian_base.h:29,
                 from /usr/local/include/CGAL/Cartesian.h:28,
                 from sweep_line.cpp:4:
/usr/local/include/CGAL/array.h:81: error: expected nested-name-specifier before '...' token
/usr/local/include/CGAL/array.h:81: error: expected '>' before '...' token
/usr/local/include/CGAL/array.h:83: error: template argument 2 is invalid
/usr/local/include/CGAL/array.h:84: error: expected ',' or '...' before '&' token
/usr/local/include/CGAL/array.h: In function 'int CGAL::make_array(const T&, int)':
/usr/local/include/CGAL/array.h:86: error: template argument 2 is invalid
/usr/local/include/CGAL/array.h:86: error: invalid type in declaration before '=' token
/usr/local/include/CGAL/array.h:86: error: 'args' was not declared in this scope
/usr/local/include/CGAL/array.h:86: error: expected `}' before '...' token
/usr/local/include/CGAL/array.h:86: error: expected `}' before '...' token
/usr/local/include/CGAL/array.h:86: error: expected ',' or ';' before '...' token
/usr/local/include/CGAL/array.h: At global scope:
/usr/local/include/CGAL/array.h:87: error: expected unqualified-id before 'return'
/usr/local/include/CGAL/array.h:88: error: expected declaration before '}' token
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.



>>>g++ sweep_line.cpp -lCGAL -I/usr/local/include/CGAL
In file included from /usr/local/include/CGAL/gmpxx_coercion_traits.h:35,
                 from /usr/local/include/CGAL/mpz_class.h:29,
                 from /usr/local/include/CGAL/gmpxx.h:47,
                 from /usr/local/include/CGAL/is_convertible.h:28,
                 from /usr/local/include/CGAL/Rational_traits.h:31,
                 from /usr/local/include/CGAL/number_type_basic.h:65,
                 from /usr/local/include/CGAL/basic.h:36,
                 from /usr/local/include/CGAL/Cartesian/Cartesian_base.h:28,
                 from /usr/local/include/CGAL/Cartesian.h:28,
                 from sweep_line.cpp:4:
/usr/local/include/mpfr.h:181: error: expected ';' before '*' token
/usr/local/include/mpfr.h:279: error: expected constructor, destructor, or type conversion before 'const'
/usr/local/include/mpfr.h:280: error: expected constructor, destructor, or type conversion before 'const'
/usr/local/include/mpfr.h:281: error: expected constructor, destructor, or type conversion before 'int'
/usr/local/include/mpfr.h:282: error: expected constructor, destructor, or type conversion before 'int'
/usr/local/include/mpfr.h:283: error: expected constructor, destructor, or type conversion before 'int'
/usr/local/include/mpfr.h:284: error: expected constructor, destructor, or type conversion before 'const'
/usr/local/include/mpfr.h:286: error: '__GMP_DECLSPEC' does not name a type
/usr/local/include/mpfr.h:287: error: expected constructor, destructor, or type conversion before 'int'
/usr/local/include/mpfr.h:288: error: '__GMP_DECLSPEC' does not name a type
/usr/local/include/mpfr.h:289: error: '__GMP_DECLSPEC' does not name a type
/usr/local/include/mpfr.h:290: error: '__GMP_DECLSPEC' does not name a type
/usr/local/include/mpfr.h:291: error: expected constructor, destructor, or type conversion before 'int'
/usr/local/include/mpfr.h:292: error: '__GMP_DECLSPEC' does not name a type
/usr/local/include/mpfr.h:293: error: '__GMP_DECLSPEC' does not name a type
/usr/local/include/mpfr.h:295: error: expected constructor, destructor, or type conversion before 'void'
/usr/local/include/mpfr.h:296: error: '__GMP_DECLSPEC' does not name a type
/usr/local/include/mpfr.h:297: error: expected constructor, destructor, or type conversion before 'const'
/usr/local/include/mpfr.h:300: error: expected constructor, destructor, or type conversion before 'void'
/usr/local/include/mpfr.h:301: error: expected constructor, destructor, or type conversion before 'void'
/usr/local/include/mpfr.h:302: error: expected constructor, destructor, or type conversion before 'void'
/usr/local/include/mpfr.h:303: error: expected constructor, destructor, or type conversion before 'void'
/usr/local/include/mpfr.h:304: error: expected constructor, destructor, or type conversion before 'void'

解决方案

You have two ways:

  1. Allow C++11 by adding corresponding flag to compiler(--std=c++11 or --std=c++0x).
  2. Define CGAL_CFG_NO_CPP0X_ARRAY, CGAL_CFG_NO_TR1_ARRAY and CGAL_CFG_NO_VARIADIC_TEMPLATES. Note: in this case you will need boost/array.hpp header.

这篇关于用CGAL编译一个简单的测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆