繁体   English   中英

无法使用CGAL运行3D表面网格生成示例

[英]Fail to run the example of 3D Surface Mesh Generation with CGAL

我正在尝试使用CGAL运行 3D表面网格生成示例 代码是:

#include <CGAL/Surface_mesh_default_triangulation_3.h>
#include <CGAL/Complex_2_in_triangulation_3.h>
#include <CGAL/make_surface_mesh.h>
#include <CGAL/Implicit_surface_3.h>
// default triangulation for Surface_mesher
typedef CGAL::Surface_mesh_default_triangulation_3 Tr;
// c2t3
typedef CGAL::Complex_2_in_triangulation_3<Tr> C2t3;
typedef Tr::Geom_traits GT;
typedef GT::Sphere_3 Sphere_3;
typedef GT::Point_3 Point_3;
typedef GT::FT FT;
typedef FT (*Function)(Point_3);
typedef CGAL::Implicit_surface_3<GT, Function> Surface_3;

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

int main() {
    Tr tr;            // 3D-Delaunay triangulation
    C2t3 c2t3 (tr);   // 2D-complex in 3D-Delaunay triangulation
    // defining the surface
    Surface_3 surface(sphere_function,             // pointer to function
                      Sphere_3(CGAL::ORIGIN, 2.)); // bounding sphere
    // Note that "2." above is the *squared* radius of the bounding sphere!
    // defining meshing criteria
    CGAL::Surface_mesh_default_criteria_3<Tr> criteria(30.,  // angular bound
                                                       0.1,  // radius bound
                                                       0.1); // distance bound
    // meshing surface
    CGAL::make_surface_mesh(c2t3, surface, criteria, CGAL::Non_manifold_tag());
    std::cout << "Final number of points: " << tr.number_of_vertices() << "\n";
}

CMakeLists文件包含:

# Created by the script cgal_create_CMakeLists
# This is the CMake script for compiling a set of CGAL applications.

cmake_minimum_required(VERSION 3.7)
project(_cgal)

# CGAL and its components
find_package( CGAL QUIET COMPONENTS Core )

if ( NOT CGAL_FOUND )

  message(STATUS "This project requires the CGAL library, and will not be compiled.")
  return()  

endif()

# include helper file
include( ${CGAL_USE_FILE} )


# Boost and its components
find_package( Boost REQUIRED )

if ( NOT Boost_FOUND )

  message(STATUS "This project requires the Boost library, and will not be compiled.")

  return()  

endif()


# Creating entries for target: out
# ############################
set(CMAKE_CXX_STANDARD 11)

set(SOURCE_FILES main.cpp)
add_executable(_cgal ${SOURCE_FILES})

add_to_cached_list( CGAL_EXECUTABLE_TARGETS _cgal )

# Link the executable to CGAL and third-party libraries
target_link_libraries(_cgal   ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES} )

cmake输出:

-- The C compiler identification is GNU 7.1.0
-- The CXX compiler identification is GNU 7.1.0
-- Checking whether C compiler has -isysroot
-- Checking whether C compiler has -isysroot - yes
-- Checking whether C compiler supports OSX deployment target flag
-- Checking whether C compiler supports OSX deployment target flag - yes
-- Check for working C compiler: /usr/local/bin/gcc-7
-- Check for working C compiler: /usr/local/bin/gcc-7 -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Checking whether CXX compiler has -isysroot
-- Checking whether CXX compiler has -isysroot - yes
-- Checking whether CXX compiler supports OSX deployment target flag
-- Checking whether CXX compiler supports OSX deployment target flag - yes
-- Check for working CXX compiler: /usr/local/bin/g++-7
-- Check for working CXX compiler: /usr/local/bin/g++-7 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Build type: Release
-- USING CXXFLAGS = ' -DNDEBUG'
-- USING EXEFLAGS = ' '
-- Targetting Unix Makefiles
-- Using /usr/local/bin/g++-7 compiler.
-- DARWIN_VERSION=16
-- Mac Leopard detected
-- Requested component: Core
-- Requested component: MPFR
-- Requested component: GMP
-- Boost version: 1.64.0
-- Configuring done
-- Generating done

但是,我收到以下错误:

Scanning dependencies of target _cgal
[ 50%] Building CXX object CMakeFiles/_cgal.dir/main.cpp.o
[100%] Linking CXX executable _cgal
Undefined symbols for architecture x86_64:
  "CGAL::get_mode(std::basic_ios<char, std::char_traits<char> >&)", referenced from:
      std::basic_ostream<char, std::char_traits<char> >& CGAL::insert<CGAL::Epick>(std::basic_ostream<char, std::char_traits<char> >&, CGAL::Point_3<CGAL::Epick> const&, CGAL::Cartesian_tag const&) in main.cpp.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make[3]: *** [_cgal] Error 1
make[2]: *** [CMakeFiles/_cgal.dir/all] Error 2
make[1]: *** [CMakeFiles/_cgal.dir/rule] Error 2
make: *** [_cgal] Error 2

如果您能向我解释如何解决此问题,我将不胜感激。

UPD: 似乎有关,但是没有得到我应该在cmake中添加的软件包。

UPD2: 我发现这可能与以下问题有关:

在OS X上有两种标准C ++库的实现:libstdc ++和libc ++。 它们与二进制文件不兼容,并且libMLi3需要libstdc ++。

默认情况下,在10.8和更早版本上选择libstdc ++,默认情况下,在10.9上选择libc ++。 为了确保与libMLi3兼容,我们需要手动选择libstdc ++。

为此,将-stdlib = libstdc ++添加到链接命令。

我在CMake文件中修改了以下行,但没有帮助:

# Link the executable to CGAL and third-party libraries
target_link_libraries(_cgal ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES}  -static-libstdc++)

UPD3:我尝试了此处建议的解决方案,但无济于事

project( _cgal )

cmake_minimum_required(VERSION 2.8.10)

find_package(CGAL QUIET COMPONENTS Core )

if ( CGAL_FOUND )

  include( ${CGAL_USE_FILE} )

  include( CGAL_CreateSingleSourceCGALProgram )

  create_single_source_cgal_program( "main.cpp" )

else()

    message(STATUS "This program requires the CGAL library, and will not be compiled.")

endif()

答案是:修复编译器! CGAL与使用clang编译器的brew一起安装。 但是要编译项目,我一直在使用g++ 我应该更经常用C ++编写代码:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM