title: How to precompile CGAL headers to speed up (Ubuntu)
body: <p>I was launching one of the examples offered by CGAL on their <a href="https://doc.cgal.org/latest/Manual/tuto_reconstruction.html" rel="nofollow noreferrer">website</a>, and I realized that the compilation time is very high, so I saw that one possibility was to generate a .h file including all the headers that are being used and precompile them.</p>
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;CGAL/Exact_predicates_inexact_constructions_kernel.h&gt;
  #include &lt;CGAL/Point_set_3.h&gt;
  #include &lt;CGAL/Point_set_3/IO.h&gt;
  #include &lt;CGAL/remove_outliers.h&gt;
  #include &lt;CGAL/grid_simplify_point_set.h&gt;
  #include &lt;CGAL/jet_smooth_point_set.h&gt;
  #include &lt;CGAL/jet_estimate_normals.h&gt;
  #include &lt;CGAL/mst_orient_normals.h&gt;
  #include &lt;CGAL/poisson_surface_reconstruction.h&gt;
  #include &lt;CGAL/Advancing_front_surface_reconstruction.h&gt;
  #include &lt;CGAL/Scale_space_surface_reconstruction_3.h&gt;
  #include &lt;CGAL/Scale_space_reconstruction_3/Jet_smoother.h&gt;
  #include &lt;CGAL/Scale_space_reconstruction_3/Advancing_front_mesher.h&gt;
  #include &lt;CGAL/Surface_mesh.h&gt;
  #include &lt;CGAL/Polygon_mesh_processing/polygon_soup_to_polygon_mesh.h&gt;
  </code></pre>
  <p>And after creating the MyHeaders.h I try to compile it using:</p>
  <pre><code>g++ -std=c++14 main.cpp -lCGAL -lboost_system -lboost_date_time -lboost_thread -lgmp -lmpfr -L/usr/local/include
  </code></pre>
  <p>But errors of many kinds are coming out. This example, as far as I know, uses CGAL, BOOST, GMP and MPFR.</p>
  <p>Does someone know how can I solve this problem? I'm using Ubuntu 20.04 with CGAL 5.4</p>
  <p>The errors:</p>
  <pre><code>/usr/local/include/CGAL/poisson_surface_reconstruction.h: In instantiation of ‘bool CGAL::poisson_surface_reconstruction_delaunay(PointInputIterator, PointInputIterator, PointMap, NormalMap, PolygonMesh&amp;, double, double, double, double, Tag) [with PointInputIterator = __gnu_cxx::__normal_iterator&lt;CGAL::Point_set_3&lt;CGAL::Point_3&lt;CGAL::Epick&gt;, CGAL::Vector_3&lt;CGAL::Epick&gt; &gt;::Index*, std::vector&lt;CGAL::Point_set_3&lt;CGAL::Point_3&lt;CGAL::Epick&gt;, CGAL::Vector_3&lt;CGAL::Epick&gt; &gt;::Index, std::allocator&lt;CGAL::Point_set_3&lt;CGAL::Point_3&lt;CGAL::Epick&gt;, CGAL::Vector_3&lt;CGAL::Epick&gt; &gt;::Index&gt; &gt; &gt;; PointMap = CGAL::Point_set_3&lt;CGAL::Point_3&lt;CGAL::Epick&gt;, CGAL::Vector_3&lt;CGAL::Epick&gt; &gt;::Property_map&lt;CGAL::Point_3&lt;CGAL::Epick&gt; &gt;; NormalMap = CGAL::Point_set_3&lt;CGAL::Point_3&lt;CGAL::Epick&gt;, CGAL::Vector_3&lt;CGAL::Epick&gt; &gt;::Property_map&lt;CGAL::Vector_3&lt;CGAL::Epick&gt; &gt;; PolygonMesh = CGAL::Surface_mesh&lt;CGAL::Point_3&lt;CGAL::Epick&gt; &gt;; Tag = CGAL::Manifold_with_boundary_tag]’:
  main.cpp:99:38:   required from here
  /usr/local/include/CGAL/poisson_surface_reconstruction.h:105:10: error: no matching function for call to ‘CGAL::Poisson_reconstruction_function&lt;CGAL::Epick&gt;::compute_implicit_function()’
    105 |     if ( ! function.compute_implicit_function() )
  In file included from /usr/local/include/CGAL/poisson_surface_reconstruction.h:21,
                   from main.cpp:9:
  /usr/local/include/CGAL/Poisson_reconstruction_function.h:417:8: note: candidate: ‘template&lt;class SparseLinearAlgebraTraits_d, class Visitor&gt; bool CGAL::Poisson_reconstruction_function&lt;Gt&gt;::compute_implicit_function(SparseLinearAlgebraTraits_d, Visitor, double, double) [with SparseLinearAlgebraTraits_d = SparseLinearAlgebraTraits_d; Visitor = Visitor; Gt = CGAL::Epick]’
    417 |   bool compute_implicit_function(
        |        ^~~~~~~~~~~~~~~~~~~~~~~~~
  /usr/local/include/CGAL/Poisson_reconstruction_function.h:417:8: note:   template argument deduction/substitution failed:
  In file included from main.cpp:9:
  /usr/local/include/CGAL/poisson_surface_reconstruction.h:105:10: note:   candidate expects 4 arguments, 0 provided
    105 |     if ( ! function.compute_implicit_function() )
  In file included from /usr/local/include/CGAL/poisson_surface_reconstruction.h:21,
                   from main.cpp:9:
  /usr/local/include/CGAL/Poisson_reconstruction_function.h:571:8: note: candidate: ‘template&lt;class SparseLinearAlgebraTraits_d&gt; bool CGAL::Poisson_reconstruction_function&lt;Gt&gt;::compute_implicit_function(SparseLinearAlgebraTraits_d, bool) [with SparseLinearAlgebraTraits_d = SparseLinearAlgebraTraits_d; Gt = CGAL::Epick]’
    571 |   bool compute_implicit_function(SparseLinearAlgebraTraits_d solver, bool smoother_hole_filling = false)
        |        ^~~~~~~~~~~~~~~~~~~~~~~~~
  /usr/local/include/CGAL/Poisson_reconstruction_function.h:571:8: note:   template argument deduction/substitution failed:
  In file included from main.cpp:9:
  /usr/local/include/CGAL/poisson_surface_reconstruction.h:105:10: note:   candidate expects 2 arguments, 0 provided
    105 |     if ( ! function.compute_implicit_function() )
  In file included from /usr/local/include/CGAL/basic.h:26,
                   from /usr/local/include/CGAL/Cartesian/Cartesian_base.h:20,
                   from /usr/local/include/CGAL/Simple_cartesian.h:20,
                   from /usr/local/include/CGAL/Exact_predicates_inexact_constructions_kernel.h:20,
                   from main.cpp:1:
  /usr/local/include/CGAL/jet_smooth_point_set.h: In instantiation of ‘void CGAL::jet_smooth_point_set(PointRange&amp;, unsigned int, const NamedParameters&amp;) [with ConcurrencyTag = CGAL::Sequential_tag; PointRange = CGAL::Point_set_3&lt;CGAL::Point_3&lt;CGAL::Epick&gt;, CGAL::Vector_3&lt;CGAL::Epick&gt; &gt;; NamedParameters = CGAL::Named_function_parameters&lt;CGAL::Epick, CGAL::internal_np::geom_traits_t, CGAL::Named_function_parameters&lt;CGAL::Point_set_3&lt;CGAL::Point_3&lt;CGAL::Epick&gt;, CGAL::Vector_3&lt;CGAL::Epick&gt; &gt;::Property_map&lt;CGAL::Vector_3&lt;CGAL::Epick&gt; &gt;, CGAL::internal_np::normal_t, CGAL::Named_function_parameters&lt;CGAL::Point_set_3&lt;CGAL::Point_3&lt;CGAL::Epick&gt;, CGAL::Vector_3&lt;CGAL::Epick&gt; &gt;::Property_map&lt;CGAL::Point_3&lt;CGAL::Epick&gt; &gt;, CGAL::internal_np::point_t, CGAL::internal_np::No_property&gt; &gt; &gt;]’:
  /usr/local/include/CGAL/jet_smooth_point_set.h:285:5:   required from ‘void CGAL::jet_smooth_point_set(PointRange&amp;, unsigned int) [with ConcurrencyTag = CGAL::Sequential_tag; PointRange = CGAL::Point_set_3&lt;CGAL::Point_3&lt;CGAL::Epick&gt;, CGAL::Vector_3&lt;CGAL::Epick&gt; &gt;]’
  main.cpp:86:65:   required from here
  /usr/local/include/CGAL/jet_smooth_point_set.h:202:3: error: static assertion failed: Error: no SVD traits
    202 |   CGAL_static_assertion_msg(!(boost::is_same&lt;SvdTraits,
        |   ^~~~~~~~~~~~~~~~~~~~~~~~~
  /usr/local/include/CGAL/jet_smooth_point_set.h: In instantiation of ‘void CGAL::jet_smooth_point_set(PointRange&amp;, unsigned int, const NamedParameters&amp;) [with ConcurrencyTag = CGAL::Sequential_tag; PointRange = CGAL::Iterator_range&lt;__gnu_cxx::__normal_iterator&lt;CGAL::Point_3&lt;CGAL::Epick&gt;*, std::vector&lt;CGAL::Point_3&lt;CGAL::Epick&gt;, std::allocator&lt;CGAL::Point_3&lt;CGAL::Epick&gt; &gt; &gt; &gt; &gt;; NamedParameters = CGAL::Named_function_parameters&lt;unsigned int, CGAL::internal_np::degree_monge_t, CGAL::Named_function_parameters&lt;unsigned int, CGAL::internal_np::degree_fitting_t, CGAL::internal_np::No_property&gt; &gt;]’:
  /usr/local/include/CGAL/Scale_space_reconstruction_3/Jet_smoother.h:83:5:   required from ‘void CGAL::Scale_space_reconstruction_3::Jet_smoother&lt;Geom_traits, ConcurrencyTag&gt;::operator()(InputIterator, InputIterator) [with InputIterator = __gnu_cxx::__normal_iterator&lt;CGAL::Point_3&lt;CGAL::Epick&gt;*, std::vector&lt;CGAL::Point_3&lt;CGAL::Epick&gt;, std::allocator&lt;CGAL::Point_3&lt;CGAL::Epick&gt; &gt; &gt; &gt;; Geom_traits = CGAL::Epick; ConcurrencyTag = CGAL::Sequential_tag]’
  /usr/local/include/CGAL/Scale_space_surface_reconstruction_3.h:180:39:   required from ‘void CGAL::Scale_space_surface_reconstruction_3&lt;Geom_traits&gt;::increase_scale(std::size_t, const Smoother&amp;) [with Smoother = CGAL::Scale_space_reconstruction_3::Jet_smoother&lt;CGAL::Epick&gt;; Geom_traits = CGAL::Epick; std::size_t = long unsigned int]’
  main.cpp:136:98:   required from here
  /usr/local/include/CGAL/jet_smooth_point_set.h:202:3: error: static assertion failed: Error: no SVD traits
  In file included from /usr/include/c++/9/functional:59,
                   from /usr/local/include/CGAL/config.h:431,
                   from /usr/local/include/CGAL/basic.h:21,
                   from /usr/local/include/CGAL/Cartesian/Cartesian_base.h:20,
                   from /usr/local/include/CGAL/Simple_cartesian.h:20,
                   from /usr/local/include/CGAL/Exact_predicates_inexact_constructions_kernel.h:20,
                   from main.cpp:1:
  /usr/include/c++/9/bits/std_function.h:667:7: error: ‘std::function&lt;_Res(_ArgTypes ...)&gt;::function(_Functor) [with _Functor = CGAL::jet_smooth_point_set(PointRange&amp;, unsigned int, const NamedParameters&amp;) [with ConcurrencyTag = CGAL::Sequential_tag; PointRange = CGAL::Point_set_3&lt;CGAL::Point_3&lt;CGAL::Epick&gt;, CGAL::Vector_3&lt;CGAL::Epick&gt; &gt;; NamedParameters = CGAL::Named_function_parameters&lt;CGAL::Epick, CGAL::internal_np::geom_traits_t, CGAL::Named_function_parameters&lt;CGAL::Point_set_3&lt;CGAL::Point_3&lt;CGAL::Epick&gt;, CGAL::Vector_3&lt;CGAL::Epick&gt; &gt;::Property_map&lt;CGAL::Vector_3&lt;CGAL::Epick&gt; &gt;, CGAL::internal_np::normal_t, CGAL::Named_function_parameters&lt;CGAL::Point_set_3&lt;CGAL::Point_3&lt;CGAL::Epick&gt;, CGAL::Vector_3&lt;CGAL::Epick&gt; &gt;::Property_map&lt;CGAL::Point_3&lt;CGAL::Epick&gt; &gt;, CGAL::internal_np::point_t, CGAL::internal_np::No_property&gt; &gt; &gt;]::&lt;lambda(const reference&amp;)&gt;; &lt;template-parameter-2-2&gt; = void; &lt;template-parameter-2-3&gt; = void; _Res = bool; _ArgTypes = {boost::tuples::cons&lt;CGAL::Point_set_3&lt;CGAL::Point_3&lt;CGAL::Epick&gt;, CGAL::Vector_3&lt;CGAL::Epick&gt; &gt;::Index&amp;, boost::tuples::cons&lt;CGAL::Point_3&lt;CGAL::Epick&gt;&amp;, boost::tuples::null_type&gt; &gt;}]’, declared using local type ‘CGAL::jet_smooth_point_set(PointRange&amp;, unsigned int, const NamedParameters&amp;) [with ConcurrencyTag = CGAL::Sequential_tag; PointRange = CGAL::Point_set_3&lt;CGAL::Point_3&lt;CGAL::Epick&gt;, CGAL::Vector_3&lt;CGAL::Epick&gt; &gt;; NamedParameters = CGAL::Named_function_parameters&lt;CGAL::Epick, CGAL::internal_np::geom_traits_t, CGAL::Named_function_parameters&lt;CGAL::Point_set_3&lt;CGAL::Point_3&lt;CGAL::Epick&gt;, CGAL::Vector_3&lt;CGAL::Epick&gt; &gt;::Property_map&lt;CGAL::Vector_3&lt;CGAL::Epick&gt; &gt;, CGAL::internal_np::normal_t, CGAL::Named_function_parameters&lt;CGAL::Point_set_3&lt;CGAL::Point_3&lt;CGAL::Epick&gt;, CGAL::Vector_3&lt;CGAL::Epick&gt; &gt;::Property_map&lt;CGAL::Point_3&lt;CGAL::Epick&gt; &gt;, CGAL::internal_np::point_t, CGAL::internal_np::No_property&gt; &gt; &gt;]::&lt;lambda(const reference&amp;)&gt;’, is used but never defined [-fpermissive]
    667 |       function&lt;_Res(_ArgTypes...)&gt;::
        |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
  /usr/include/c++/9/bits/std_function.h:667:7: error: ‘std::function&lt;_Res(_ArgTypes ...)&gt;::function(_Functor) [with _Functor = CGAL::jet_smooth_point_set(PointRange&amp;, unsigned int, const NamedParameters&amp;) [with ConcurrencyTag = CGAL::Sequential_tag; PointRange = CGAL::Point_set_3&lt;CGAL::Point_3&lt;CGAL::Epick&gt;, CGAL::Vector_3&lt;CGAL::Epick&gt; &gt;; NamedParameters = CGAL::Named_function_parameters&lt;CGAL::Epick, CGAL::internal_np::geom_traits_t, CGAL::Named_function_parameters&lt;CGAL::Point_set_3&lt;CGAL::Point_3&lt;CGAL::Epick&gt;, CGAL::Vector_3&lt;CGAL::Epick&gt; &gt;::Property_map&lt;CGAL::Vector_3&lt;CGAL::Epick&gt; &gt;, CGAL::internal_np::normal_t, CGAL::Named_function_parameters&lt;CGAL::Point_set_3&lt;CGAL::Point_3&lt;CGAL::Epick&gt;, CGAL::Vector_3&lt;CGAL::Epick&gt; &gt;::Property_map&lt;CGAL::Point_3&lt;CGAL::Epick&gt; &gt;, CGAL::internal_np::point_t, CGAL::internal_np::No_property&gt; &gt; &gt;]::&lt;lambda(const reference&amp;)&gt;; &lt;template-parameter-2-2&gt; = void; &lt;template-parameter-2-3&gt; = void; _Res = bool; _ArgTypes = {boost::tuples::cons&lt;CGAL::Point_set_3&lt;CGAL::Point_3&lt;CGAL::Epick&gt;, CGAL::Vector_3&lt;CGAL::Epick&gt; &gt;::Index&amp;, boost::tuples::cons&lt;CGAL::Point_3&lt;CGAL::Epick&gt;&amp;, boost::tuples::null_type&gt; &gt;}]’, declared using local type ‘CGAL::jet_smooth_point_set(PointRange&amp;, unsigned int, const NamedParameters&amp;) [with ConcurrencyTag = CGAL::Sequential_tag; PointRange = CGAL::Point_set_3&lt;CGAL::Point_3&lt;CGAL::Epick&gt;, CGAL::Vector_3&lt;CGAL::Epick&gt; &gt;; NamedParameters = CGAL::Named_function_parameters&lt;CGAL::Epick, CGAL::internal_np::geom_traits_t, CGAL::Named_function_parameters&lt;CGAL::Point_set_3&lt;CGAL::Point_3&lt;CGAL::Epick&gt;, CGAL::Vector_3&lt;CGAL::Epick&gt; &gt;::Property_map&lt;CGAL::Vector_3&lt;CGAL::Epick&gt; &gt;, CGAL::internal_np::normal_t, CGAL::Named_function_parameters&lt;CGAL::Point_set_3&lt;CGAL::Point_3&lt;CGAL::Epick&gt;, CGAL::Vector_3&lt;CGAL::Epick&gt; &gt;::Property_map&lt;CGAL::Point_3&lt;CGAL::Epick&gt; &gt;, CGAL::internal_np::point_t, CGAL::internal_np::No_property&gt; &gt; &gt;]::&lt;lambda(const reference&amp;)&gt;’, is used but never defined [-fpermissive]
  /usr/include/c++/9/bits/std_function.h:667:7: error: ‘std::function&lt;_Res(_ArgTypes ...)&gt;::function(_Functor) [with _Functor = CGAL::jet_smooth_point_set(PointRange&amp;, unsigned int, const NamedParameters&amp;) [with ConcurrencyTag = CGAL::Sequential_tag; PointRange = CGAL::Iterator_range&lt;__gnu_cxx::__normal_iterator&lt;CGAL::Point_3&lt;CGAL::Epick&gt;*, std::vector&lt;CGAL::Point_3&lt;CGAL::Epick&gt;, std::allocator&lt;CGAL::Point_3&lt;CGAL::Epick&gt; &gt; &gt; &gt; &gt;; NamedParameters = CGAL::Named_function_parameters&lt;unsigned int, CGAL::internal_np::degree_monge_t, CGAL::Named_function_parameters&lt;unsigned int, CGAL::internal_np::degree_fitting_t, CGAL::internal_np::No_property&gt; &gt;]::&lt;lambda(const reference&amp;)&gt;; &lt;template-parameter-2-2&gt; = void; &lt;template-parameter-2-3&gt; = void; _Res = bool; _ArgTypes = {boost::tuples::cons&lt;CGAL::Point_3&lt;CGAL::Epick&gt;&amp;, boost::tuples::cons&lt;CGAL::Point_3&lt;CGAL::Epick&gt;&amp;, boost::tuples::null_type&gt; &gt;}]’, declared using local type ‘CGAL::jet_smooth_point_set(PointRange&amp;, unsigned int, const NamedParameters&amp;) [with ConcurrencyTag = CGAL::Sequential_tag; PointRange = CGAL::Iterator_range&lt;__gnu_cxx::__normal_iterator&lt;CGAL::Point_3&lt;CGAL::Epick&gt;*, std::vector&lt;CGAL::Point_3&lt;CGAL::Epick&gt;, std::allocator&lt;CGAL::Point_3&lt;CGAL::Epick&gt; &gt; &gt; &gt; &gt;; NamedParameters = CGAL::Named_function_parameters&lt;unsigned int, CGAL::internal_np::degree_monge_t, CGAL::Named_function_parameters&lt;unsigned int, CGAL::internal_np::degree_fitting_t, CGAL::internal_np::No_property&gt; &gt;]::&lt;lambda(const reference&amp;)&gt;’, is used but never defined [-fpermissive]
  /usr/include/c++/9/bits/std_function.h:667:7: error: ‘std::function&lt;_Res(_ArgTypes ...)&gt;::function(_Functor) [with _Functor = CGAL::jet_smooth_point_set(PointRange&amp;, unsigned int, const NamedParameters&amp;) [with ConcurrencyTag = CGAL::Sequential_tag; PointRange = CGAL::Iterator_range&lt;__gnu_cxx::__normal_iterator&lt;CGAL::Point_3&lt;CGAL::Epick&gt;*, std::vector&lt;CGAL::Point_3&lt;CGAL::Epick&gt;, std::allocator&lt;CGAL::Point_3&lt;CGAL::Epick&gt; &gt; &gt; &gt; &gt;; NamedParameters = CGAL::Named_function_parameters&lt;unsigned int, CGAL::internal_np::degree_monge_t, CGAL::Named_function_parameters&lt;unsigned int, CGAL::internal_np::degree_fitting_t, CGAL::internal_np::No_property&gt; &gt;]::&lt;lambda(const reference&amp;)&gt;; &lt;template-parameter-2-2&gt; = void; &lt;template-parameter-2-3&gt; = void; _Res = bool; _ArgTypes = {boost::tuples::cons&lt;CGAL::Point_3&lt;CGAL::Epick&gt;&amp;, boost::tuples::cons&lt;CGAL::Point_3&lt;CGAL::Epick&gt;&amp;, boost::tuples::null_type&gt; &gt;}]’, declared using local type ‘CGAL::jet_smooth_point_set(PointRange&amp;, unsigned int, const NamedParameters&amp;) [with ConcurrencyTag = CGAL::Sequential_tag; PointRange = CGAL::Iterator_range&lt;__gnu_cxx::__normal_iterator&lt;CGAL::Point_3&lt;CGAL::Epick&gt;*, std::vector&lt;CGAL::Point_3&lt;CGAL::Epick&gt;, std::allocator&lt;CGAL::Point_3&lt;CGAL::Epick&gt; &gt; &gt; &gt; &gt;; NamedParameters = CGAL::Named_function_parameters&lt;unsigned int, CGAL::internal_np::degree_monge_t, CGAL::Named_function_parameters&lt;unsigned int, CGAL::internal_np::degree_fitting_t, CGAL::internal_np::No_property&gt; &gt;]::&lt;lambda(const reference&amp;)&gt;’, is used but never defined [-fpermissive]
  
  </code></pre>
  <p><strong>Edit</strong>: Add CMakeLists.txt</p>
  <pre><code>cmake_minimum_required(VERSION 3.22)
  project(CGAL_V0)
  
  set(Qt5_DIR &quot;/opt/Qt/5.15.2/gcc_64/lib/cmake/Qt5/&quot;)
  set(CGAL_DATA_DIR &quot;/usr/include/CGAL&quot;)
  set(CGAL_DO_NOT_WARN_ABOUT_CMAKE_BUILD_TYPE TRUE)
  
  find_package(CGAL REQUIRED COMPONENTS Core)
  
  find_package(GMP REQUIRED)
  message(STATUS &quot;GMP Found: ${GMP_FOUND}&quot;)
  message(STATUS &quot;GMP Libs: ${GMP_LIBRARIES}&quot;)
  
  find_package(MPFR REQUIRED)
  message(STATUS &quot;MPFR Found: ${MPFR_FOUND}&quot;)
  message(STATUS &quot;MPFR Libs: ${MPFR_LIBRARIES}&quot;)
  
  find_package(Eigen3 REQUIRED)
  include_directories(${EIGEN3_INCLUDE_DIR})
  message(STATUS &quot;Eigen3 Found: ${EIGEN3_FOUND}&quot;)
  message(STATUS &quot;Eigen3 DIR: ${EIGEN3_INCLUDE_DIR}&quot;)
  
  set(CMAKE_CXX_STANDARD 14)
  
  add_executable(CGAL_V0 main.cpp)
  target_link_libraries(CGAL_V0 CGAL::CGAL CGAL::CGAL_Core ${MPFR_LIBRARIES} ${GMP_LIBRARIES})
  </code></pre>