2

我刚刚在 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'
4

2 回答 2

4

您应该使用 -I/usr/local/include 而不是 -I/usr/local/include/CGAL

于 2013-05-10T07:26:15.117 回答
3

你有两种方法:

  1. --std=c++11通过向编译器(或--std=c++0x)添加相应的标志来允许 C++11 。
  2. 定义和。CGAL_CFG_NO_CPP0X_ARRAY_ 注意:在这种情况下,您将需要标题。CGAL_CFG_NO_TR1_ARRAYCGAL_CFG_NO_VARIADIC_TEMPLATESboost/array.hpp
于 2013-05-09T14:20:29.570 回答