CGAL: как мне успешно скомпилировать и связать примеры CGAL (в Mac OS X 10.9 Mavericks)

Я обнаружил, что примеры CGAL не компилируются под Mac OS X 10.9 (Mavericks). Вы можете успешно скомпилировать основную библиотеку CGAL 4.3, а также связать ее, но при использовании определенных типов библиотеки я получаю ошибки, как показано ниже.

Конкретно меня заинтересовал пример Surface_reconstruction_points_3, который я пытался собрать изначально, получая такую ​​ошибку:

Linking CXX executable poisson_reconstruction
Undefined symbols for architecture x86_64:
  "CGAL::File_writer_OFF::write_header(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, unsigned long, unsigned long, unsigned long, bool)", referenced from:
      void CGAL::generic_print_polyhedron<CGAL::Polyhedron_3<CGAL::Epick, CGAL::Polyhedron_items_3, CGAL::HalfedgeDS_default, std::__1::allocator<int> >, CGAL::File_writer_OFF>(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, CGAL::Polyhedron_3<CGAL::Epick, CGAL::Polyhedron_items_3, CGAL::HalfedgeDS_default, std::__1::allocator<int> > const&, CGAL::File_writer_OFF&) in poisson_reconstruction.cpp.o
  "CGAL::is_binary(std::__1::basic_ios<char, std::__1::char_traits<char> >&)", referenced from:
      _main in poisson_reconstruction.cpp.o
  "CGAL::is_pretty(std::__1::basic_ios<char, std::__1::char_traits<char> >&)", referenced from:
      _main in poisson_reconstruction.cpp.o
  "CGAL::operator>>(std::__1::basic_istream<char, std::__1::char_traits<char> >&, CGAL::File_header_OFF&)", referenced from:
      CGAL::Polyhedron_scan_OFF<CGAL::HalfedgeDS_default<CGAL::Epick, CGAL::I_Polyhedron_derived_items_3<CGAL::Polyhedron_items_3>, std::__1::allocator<int> > >::operator()(CGAL::HalfedgeDS_default<CGAL::Epick, CGAL::I_Polyhedron_derived_items_3<CGAL::Polyhedron_items_3>, std::__1::allocator<int> >&) in poisson_reconstruction.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [poisson_reconstruction] Error 1
make[1]: *** [CMakeFiles/poisson_reconstruction.dir/all] Error 2
make: *** [all] Error 2

Чтобы быть очень конкретным, я действительно интересовался функцией CGAL::make_normal_of_point_with_normal_pmap и создал тестовый пример, просто чтобы попробовать и использовать его. Однако я получаю сообщение об ошибке при компиляции этого кода (ниже).

#include <stdio.h>
#include <vector>

#include <CGAL/trace.h>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/Surface_mesh_default_criteria_3.h>
#include <CGAL/Surface_mesh_default_triangulation_3.h>
#include <CGAL/make_surface_mesh.h>
#include <CGAL/Implicit_surface_3.h>
#include <CGAL/IO/output_surface_facets_to_polyhedron.h>
#include <CGAL/Poisson_reconstruction_function.h>
#include <CGAL/Point_with_normal_3.h>
#include <CGAL/property_map.h>
#include <CGAL/compute_average_spacing.h>
#include <CGAL/Gray_level_image_3.h>

#include <CGAL/IO/Polyhedron_iostream.h>
#include <CGAL/IO/read_xyz_points.h>
#include <CGAL/IO/Complex_2_in_triangulation_3_file_writer.h>

typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef Kernel::FT FT;
typedef Kernel::Point_3 Point;
typedef Kernel::Vector_3 Vector;
typedef Kernel::Sphere_3 Sphere;

typedef CGAL::Point_with_normal_3<Kernel> Point_with_normal;
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
typedef CGAL::Poisson_reconstruction_function<Kernel> Poisson_reconstruction_function;
typedef CGAL::Surface_mesh_default_triangulation_3 STr;
typedef CGAL::Surface_mesh_complex_2_in_triangulation_3<STr> C2t3;
typedef CGAL::Implicit_surface_3<Kernel, Poisson_reconstruction_function> Surface_3;

typedef STr::Geom_traits STrGT;
typedef FT (*Function)(Point);
typedef CGAL::Implicit_surface_3<STrGT, Function> ImplSurface;
typedef CGAL::Gray_level_image_3<FT, Point> Gray_level_image;
typedef CGAL::Implicit_surface_3<STrGT, Gray_level_image> Gray_level_surface;

FT sphere_function (Point p) {
  const FT x2=p.x()*p.x(), y2=p.y()*p.y(), z2=p.z()*p.z();
  return x2+y2+z2-100;
}


int main(void)
{
    printf("Hello, world!\n");


    std::vector<Point_with_normal> points;
    for (double d=0.0; d<10.0; d+=1.0)
    {
        Point_with_normal p( 0.0, 1.0*(d), 1.0*(d*d), Vector(0.0, 1.0, 0.0) );
        points.push_back(p);
    }

    Poisson_reconstruction_function function(points.begin(), points.end(),
                                             CGAL::make_normal_of_point_with_normal_pmap(points.begin()) );

    return 0;
}

И соответствующее сообщение об ошибке:

[100%] Building CXX object CMakeFiles/cgal_test.dir/cgal_test.cpp.o
/usr/bin/c++   -DCGAL_USE_GMP -DCGAL_USE_MPFR -DWITH_CGAL -O3 -DNDEBUG -isystem /usr/local/include -I/Users/chris/dev/intern/test/cgal_testing/build -I/usr/local/Cellar/cgal/4.3/include    -o CMakeFiles/cgal_test.dir/cgal_test.cpp.o -c /Users/chris/dev/intern/test/cgal_testing/cgal_test.cpp
In file included from /Users/chris/dev/intern/test/cgal_testing/cgal_test.cpp:5:
In file included from /usr/local/Cellar/cgal/4.3/include/CGAL/Exact_predicates_inexact_constructions_kernel.h:28:
In file included from /usr/local/Cellar/cgal/4.3/include/CGAL/Simple_cartesian.h:28:
In file included from /usr/local/Cellar/cgal/4.3/include/CGAL/Cartesian/Cartesian_base.h:28:
In file included from /usr/local/Cellar/cgal/4.3/include/CGAL/basic.h:46:
In file included from /usr/local/Cellar/cgal/4.3/include/CGAL/kernel_basic.h:34:
/usr/local/Cellar/cgal/4.3/include/CGAL/Kernel_traits.h:33:23: error: no type named 'R' in
      'std::__1::__wrap_iter<CGAL::Point_with_normal_3<CGAL::Epick> *>'
  typedef typename T::R Kernel;
          ~~~~~~~~~~~~^
/usr/local/Cellar/cgal/4.3/include/CGAL/Point_with_normal_3.h:169:18: note: in instantiation of template class
      'CGAL::Kernel_traits<std::__1::__wrap_iter<CGAL::Point_with_normal_3<CGAL::Epick> *> >' requested here
  typename CGAL::Kernel_traits<Point_with_normal>::Kernel>
                 ^
/usr/local/Cellar/cgal/4.3/include/CGAL/Point_with_normal_3.h:170:3: note: while substituting deduced template arguments into function template
      'make_normal_of_point_with_normal_pmap' [with Point_with_normal = std::__1::__wrap_iter<CGAL::Point_with_normal_3<CGAL::Epick> *>]
  make_normal_of_point_with_normal_pmap(Point_with_normal)
  ^
/Users/chris/dev/intern/test/cgal_testing/cgal_test.cpp:60:13: error: no matching function for call to 'make_normal_of_point_with_normal_pmap'
                                                                                         CGAL::make_normal_of_point_with_normal_pmap(points.begin()) );
                                                                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/Cellar/cgal/4.3/include/CGAL/Point_with_normal_3.h:170:3: note: candidate template ignored: substitution failure [with Point_with_normal =
      std::__1::__wrap_iter<CGAL::Point_with_normal_3<CGAL::Epick> *>]
  make_normal_of_point_with_normal_pmap(Point_with_normal)
  ^
2 errors generated.
make[2]: *** [CMakeFiles/cgal_test.dir/cgal_test.cpp.o] Error 1
make[1]: *** [CMakeFiles/cgal_test.dir/all] Error 2
make: *** [all] Error 2

Как и следовало ожидать, стандартный способ построения всех примеров также вызывает ошибки (здесь я попытался собрать все примеры CGAL). Чтобы добраться туда, я использовал cmake для сборки библиотеки CGAL 4.3 из исходного кода и включил WITH_examples в настройках. При компиляции я вызвал make и make examples, что привело к этой ошибке:

    [ 15%] Building CXX object examples/Segment_Delaunay_graph_2/CMakeFiles/sdg-info-set.dir/sdg-info-set.cpp.o
Linking CXX executable Compute_Ridges_Umbilics
Undefined symbols for architecture x86_64:
  "boost::program_options::to_internal(std::string const&)", referenced from:
      std::vector<std::string, std::allocator<std::string> > boost::program_options::to_internal<std::string>(std::vector<std::string, std::allocator<std::string> > const&) in Compute_Ridges_Umbilics.cpp.o
  "boost::program_options::options_description::options_description(std::string const&, unsigned int, unsigned int)", referenced from:
      _main in Compute_Ridges_Umbilics.cpp.o
  "boost::program_options::invalid_option_value::invalid_option_value(std::string const&)", referenced from:
      void boost::program_options::validate<double, char>(boost::any&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, double*, long) in Compute_Ridges_Umbilics.cpp.o
      void boost::program_options::validate<unsigned int, char>(boost::any&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, unsigned int*, long) in Compute_Ridges_Umbilics.cpp.o
  "boost::program_options::error_with_option_name::error_with_option_name(std::string const&, std::string const&, std::string const&, int)", referenced from:
      std::basic_string<char, std::char_traits<char>, std::allocator<char> > const& boost::program_options::validators::get_single_string<char>(std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, bool) in Compute_Ridges_Umbilics.cpp.o
  "boost::program_options::detail::cmdline::set_additional_parser(boost::function1<std::pair<std::string, std::string>, std::string const&>)", referenced from:
      boost::program_options::basic_command_line_parser<char>::extra_parser(boost::function1<std::pair<std::string, std::string>, std::string const&>) in Compute_Ridges_Umbilics.cpp.o
  "boost::program_options::detail::cmdline::cmdline(std::vector<std::string, std::allocator<std::string> > const&)", referenced from:
      boost::program_options::basic_command_line_parser<char>::basic_command_line_parser(int, char const* const*) in Compute_Ridges_Umbilics.cpp.o
  "boost::program_options::validate(boost::any&, std::vector<std::string, std::allocator<std::string> > const&, std::string*, int)", referenced from:
      boost::program_options::typed_value<std::string, char>::xparse(boost::any&, std::vector<std::string, std::allocator<std::string> > const&) const in Compute_Ridges_Umbilics.cpp.o
  "boost::program_options::validate(boost::any&, std::vector<std::string, std::allocator<std::string> > const&, bool*, int)", referenced from:
      boost::program_options::typed_value<bool, char>::xparse(boost::any&, std::vector<std::string, std::allocator<std::string> > const&) const in Compute_Ridges_Umbilics.cpp.o
  "boost::program_options::operator<<(std::ostream&, boost::program_options::options_description const&)", referenced from:
      _main in Compute_Ridges_Umbilics.cpp.o
  "boost::program_options::error_with_option_name::substitute_placeholders(std::string const&) const", referenced from:
      vtable for boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::program_options::invalid_option_value> > in Compute_Ridges_Umbilics.cpp.o
      vtable for boost::exception_detail::error_info_injector<boost::program_options::invalid_option_value> in Compute_Ridges_Umbilics.cpp.o
      vtable for boost::program_options::invalid_option_value in Compute_Ridges_Umbilics.cpp.o
      vtable for boost::program_options::validation_error in Compute_Ridges_Umbilics.cpp.o
      vtable for boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::program_options::validation_error> > in Compute_Ridges_Umbilics.cpp.o
      vtable for boost::exception_detail::error_info_injector<boost::program_options::validation_error> in Compute_Ridges_Umbilics.cpp.o
  "boost::program_options::value_semantic_codecvt_helper<char>::parse(boost::any&, std::vector<std::string, std::allocator<std::string> > const&, bool) const", referenced from:
      vtable for boost::program_options::typed_value<bool, char> in Compute_Ridges_Umbilics.cpp.o
      vtable for boost::program_options::typed_value<double, char> in Compute_Ridges_Umbilics.cpp.o
      vtable for boost::program_options::typed_value<unsigned int, char> in Compute_Ridges_Umbilics.cpp.o
      vtable for boost::program_options::typed_value<std::string, char> in Compute_Ridges_Umbilics.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [examples/Ridges_3/Compute_Ridges_Umbilics] Error 1
make[2]: *** [examples/Ridges_3/CMakeFiles/Compute_Ridges_Umbilics.dir/all] Error 2
make[2]: *** Waiting for unfinished jobs....

В конце концов, если у вас есть идеи, как заставить функцию make_normal_of_point_with_normal_pmap снова работать, это было бы великолепно. Мне на самом деле не нужно собирать все примеры, но я хотел бы снова использовать эту часть CGAL. Спасибо!


person Chris    schedule 30.10.2013    source источник
comment
Вы используете один и тот же компилятор для компиляции библиотеки и примера? Я предполагаю, что вы используете CMakeLists, поставляемые с библиотекой?   -  person sloriot    schedule 30.10.2013
comment
да, я использую предоставленные CMakeLists и использовал тот же компилятор (g++ v4.7) - хотя я не уверен, как был скомпилирован boost, и могу попытаться переустановить его с нуля   -  person Chris    schedule 31.10.2013


Ответы (1)


Я не совсем согласен с CGAL, но рискну предположить, что у вас есть часть кода, скомпилированная с помощью libc++, и часть кода, скомпилированная с помощью libstdc++.

person Petesh    schedule 30.10.2013
comment
Я думаю, что вы что-то здесь понимаете - кажется, OS 10.9 хочет связать с libc++ по умолчанию (mathematica.stackexchange.com/questions/34692/). Обычно я собираю все с помощью libstdc++, но, поскольку я использую homebrew для установки boost, это предварительная версия (Mavericks), связанная с libc++... - person Chris; 31.10.2013