用CGAL编译一个简单的测试

compile a simple test with CGAL

本文关键字:一个 简单 测试 CGAL 编译      更新时间:2023-10-16

我刚刚在mac系统上安装了CGAL和brew。现在我很兴奋地用一个简单而最小的例子来尝试它。我怎样才能用g++编译它?

我想编译这个示例文件:

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

和我得到很多错误…(我觉得太多了,不能粘贴在这里)

作为示例文件,我使用

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;
}
编辑:

>>> 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'

您应该使用我/usr/地方/包括而不是我/usr/地方/include/CGAL

有两种方法:

  1. 允许c++ 11在编译器(--std=c++11--std=c++0x)上添加相应的标志。
  2. 定义CGAL_CFG_NO_CPP0X_ARRAYCGAL_CFG_NO_TR1_ARRAYCGAL_CFG_NO_VARIADIC_TEMPLATES。注意:在这种情况下,你将需要boost/array.hpp头。
相关文章: