Closed redantlabs closed 7 years ago
That is not a bug, but a misuse of CMake. If you want to link against libmpfr.a and libgmp.a then set the CMake variables GMP_LIBRARIES
and MPFR_LIBRARIES
accordingly in the CMake cache.
Anyway, if you use CGAL_HEADER_ONLY=ON
, then there is no longer any CGAL library, and it is neither shared nor static.
The doc is ambiguous and must probably fixed. Here we have: "These setting affect the variants of third-party libraries (see next section) selected whenever the choice is available."
These setting affect the variants of third-party libraries (see next section) selected whenever the choice is available.
That sentence is true for Boost libraries, because FindBoost..cmake
has a variable Boost_USE_STATIC_LIBS
that can be used, but CMake does not provide any way to restrict find_library
to static libraries.
You mean that in "the choice is available" the choice means "supported by FindFooBar.cmake" and not that "the static lib"?
Right. And in practice, that variable only affects the variant of Boost libraries.
We should remove the sentence from the manual, because it is wrong.
The doc bug has been fixed in the branch targeting CGAL-4.11.1, by the PR #2476.
Hi,
I am struggling with the same problem.
cmake . -DCGAL_HEADER_ONLY=ON -DBUILD_SHARED_LIBS=OFF -DMPFR_LIBRARIES=/use<path/to/libmpfr.a> -DGMP_LIBRARIES=<path/to/libgmp.a>
I generate CGAL (5.1.1) with the command above and I can see that it links to the static libraries of gmp and mpfr. However, when I try to build my own project I always get the following error:
/usr/lib/x86_64-linux-gnu/libmpfr.a(mpfr-gmp.o): In function `mpfr_tmp_allocate':
(.text+0x3b): undefined reference to `__gmp_get_memory_functions'
(.text+0x54): undefined reference to `__gmp_get_memory_functions'
/usr/lib/x86_64-linux-gnu/libmpfr.a(mpfr-gmp.o): In function `mpfr_tmp_free':
(.text+0xe9): undefined reference to `__gmp_get_memory_functions'
(.text+0x105): undefined reference to `__gmp_get_memory_functions'
/usr/lib/x86_64-linux-gnu/libmpfr.a(mpfr-gmp.o): In function `mpfr_allocate_func':
(.text.hot+0x26): undefined reference to `__gmp_get_memory_functions'
/usr/lib/x86_64-linux-gnu/libmpfr.a(mpfr-gmp.o):(.text.hot+0x7f): more undefined references to `__gmp_get_memory_functions' follow
/usr/lib/x86_64-linux-gnu/libmpfr.a(div.o): In function `mpfr_div':
(.text.hot+0x2e1): undefined reference to `__gmpn_divrem'
(.text.hot+0x551): undefined reference to `__gmpz_sizeinbase'
(.text.hot+0x58d): undefined reference to `__gmpz_sizeinbase'
(.text.hot+0x5d4): undefined reference to `__gmpz_tdiv_q'
(.text.hot+0x5e1): undefined reference to `__gmpz_sizeinbase'
(.text.hot+0x601): undefined reference to `__gmpz_scan1'
(.text.hot+0x644): undefined reference to `__gmpz_scan0'
(.text.hot+0x137f): undefined reference to `__gmpz_mul_2exp'
/usr/lib/x86_64-linux-gnu/libmpfr.a(pool.o): In function `mpfr_free_pool':
(.text+0x33): undefined reference to `__gmpz_clear'
/usr/lib/x86_64-linux-gnu/libmpfr.a(pool.o): In function `mpfr_mpz_init':
(.text.hot+0x39): undefined reference to `__gmpz_init'
/usr/lib/x86_64-linux-gnu/libmpfr.a(pool.o): In function `mpfr_mpz_init2':
(.text.hot+0x81): undefined reference to `__gmpz_init2'
/usr/lib/x86_64-linux-gnu/libmpfr.a(pool.o): In function `mpfr_mpz_clear':
(.text.hot+0xc9): undefined reference to `__gmpz_clear'
/usr/lib/x86_64-linux-gnu/libmpfr.a(round_prec.o): In function `mpfr_round_raw':
(.text+0x426): undefined reference to `__gmpn_copyd'
/usr/lib/x86_64-linux-gnu/libmpfr.a(round_prec.o): In function `mpfr_round_raw_4':
(.text+0xd3d): undefined reference to `__gmpn_copyd'
/usr/lib/x86_64-linux-gnu/libmpfr.a(round_prec.o): In function `mpfr_prec_round':
(.text+0x1776): undefined reference to `__gmpn_copyd'
/usr/lib/x86_64-linux-gnu/libmpfr.a(get_z_exp.o): In function `mpfr_get_z_2exp':
(.text+0x45): undefined reference to `__gmpz_realloc2'
(.text+0xaf): undefined reference to `__gmpz_set_ui'
/usr/lib/x86_64-linux-gnu/libmpfr.a(mulders.o): In function `mpfr_divhigh_n':
(.text+0x49d): undefined reference to `__gmpn_divrem'
(.text+0x85e): undefined reference to `__gmpn_divrem'
collect2: error: ld returned 1 exit status
CMakeFiles/sure.dir/build.make:137: recipe for target 'sure' failed
make[2]: *** [sure] Error 1
CMakeFiles/Makefile2:243: recipe for target 'CMakeFiles/sure.dir/all' failed
make[1]: *** [CMakeFiles/sure.dir/all] Error 2
Makefile:102: recipe for target 'all' failed
make: *** [all] Error 2
That is not a bug, but a misuse of CMake. If you want to link against libmpfr.a and libgmp.a then set the CMake variables
GMP_LIBRARIES
andMPFR_LIBRARIES
accordingly in the CMake cache.Anyway, if you use
CGAL_HEADER_ONLY=ON
, then there is no longer any CGAL library, and it is neither shared nor static.
I also tried this but did not succeed.
How exactly could I statically compile a program that uses CGAL?
I generate CGAL (5.1.1) with the command above and I can see that it links to the static libraries of gmp and mpfr. However, when I try to build my own project I always get the following error: [...]
Can you please copy-paste the compiler/linker command line that creates that error. It seems the GMP and MPFR libraries are not ordered correctly, when linked statically.
Of CGAL:
cmake .. -DCGAL_HEADER_ONLY=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Release -DMPFR_LIBRARIES=/usr/lib/x86_64-linux-gnu/libmpfr.a -DGMP_LIBRARIES=/usr/lib/x86_64-linux-gnu/libgmp.a -DGMPXX_LIBRARIES=/usr/lib/x86_64-linux-gnu/libgmpxx.a
== CMake setup ==
-- The CXX compiler identification is GNU 7.5.0
-- The C compiler identification is GNU 7.5.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
== CMake setup (DONE) ==
== Setting paths ==
-- Build CGAL from n/a-branch: n/a
-- Removed not-a-package: .gitattributes;.github;.gitignore;.travis;.travis.yml;CGALConfig.cmake;CGALConfigVersion.cmake;Documentation;INSTALL.md;LICENSE.md;Miscellany;README.md;build;build_static;ccpp.yml;cmake_uninstall.cmake.in
-- Installation package directory: /home/adminlocal/PhD/cpp/cgal-5.1.1/Installation
-- Maintenance package directory: /home/adminlocal/PhD/cpp/cgal-5.1.1/Maintenance
-- Core package directory: /home/adminlocal/PhD/cpp/cgal-5.1.1/Core
-- Packagenames: AABB_tree;Advancing_front_surface_reconstruction;Algebraic_foundations;Algebraic_kernel_d;Algebraic_kernel_for_circles;Algebraic_kernel_for_spheres;Alpha_shapes_2;Alpha_shapes_3;Apollonius_graph_2;Arithmetic_kernel;Arrangement_on_surface_2;BGL;Barycentric_coordinates_2;Boolean_set_operations_2;Bounding_volumes;Box_intersection_d;CGAL_Core;CGAL_ImageIO;CGAL_ipelets;Cartesian_kernel;Circular_kernel_2;Circular_kernel_3;Circulator;Classification;Combinatorial_map;Cone_spanners_2;Convex_decomposition_3;Convex_hull_2;Convex_hull_3;Convex_hull_d;Distance_2;Distance_3;Envelope_2;Envelope_3;Filtered_kernel;Generalized_map;Generator;Geomview;GraphicsView;HalfedgeDS;Hash_map;Heat_method_3;Homogeneous_kernel;Hyperbolic_triangulation_2;Inscribed_areas;Installation;Interpolation;Intersections_2;Intersections_3;Interval_skip_list;Interval_support;Inventor;Jet_fitting_3;Kernel_23;Kernel_d;LEDA;Linear_cell_complex;MacOSX;Maintenance;Matrix_search;Mesh_2;Mesh_3;Mesher_level;Minkowski_sum_2;Minkowski_sum_3;Modifier;Modular_arithmetic;Nef_2;Nef_3;Nef_S2;NewKernel_d;Number_types;OpenNL;Optimal_bounding_box;Optimal_transportation_reconstruction_2;Optimisation_basic;Partition_2;Periodic_2_triangulation_2;Periodic_3_mesh_3;Periodic_3_triangulation_3;Periodic_4_hyperbolic_triangulation_2;Point_set_2;Point_set_3;Point_set_processing_3;Poisson_surface_reconstruction_3;Polygon;Polygon_mesh_processing;Polygonal_surface_reconstruction;Polyhedron;Polyhedron_IO;Polyline_simplification_2;Polynomial;Polytope_distance_d;Principal_component_analysis;Principal_component_analysis_LGPL;Profiling_tools;Property_map;QP_solver;Random_numbers;Ridges_3;STL_Extension;Scale_space_reconstruction_3;Scripts;SearchStructures;Segment_Delaunay_graph_2;Segment_Delaunay_graph_Linf_2;Set_movable_separability_2;Shape_detection;Skin_surface_3;Snap_rounding_2;Solver_interface;Spatial_searching;Spatial_sorting;Straight_skeleton_2;Stream_lines_2;Stream_support;Subdivision_method_3;Surface_mesh;Surface_mesh_approximation;Surface_mesh_deformation;Surface_mesh_parameterization;Surface_mesh_segmentation;Surface_mesh_shortest_path;Surface_mesh_simplification;Surface_mesh_skeletonization;Surface_mesh_topology;Surface_mesher;Surface_sweep_2;TDS_2;TDS_3;Testsuite;Tetrahedral_remeshing;Three;Triangulation;Triangulation_2;Triangulation_3;Union_find;Visibility_2;Voronoi_diagram_2;wininst
== Setting paths (DONE) ==
== Generate version files ==
-- CGAL_VERSION is 5.1.1-I-900
-- CGAL_VERSION_NR is 1050110900
-- CGAL_GIT_HASH is
-- CGAL_CREATED_SVN_REVISION is 99999 (dummy)
-- CGAL_MAJOR_VERSION=5
-- CGAL_MINOR_VERSION=1
-- CGAL_BUGFIX_VERSION=1
-- CGAL_BUILD_VERSION=900
-- CGAL_SONAME_VERSION=13
-- CGAL_SOVERSION =13.0.3
-- Building static libraries
-- Targetting Unix Makefiles
-- Using /usr/bin/c++ compiler.
-- USING CMake version: 3.18.0
-- System: Linux
-- USING GCC_VERSION = '7.5.0'
-- Using gcc version 4 or later. Adding -frounding-math
== Generate version files (DONE) ==
-- Build type: Release
-- USING CXXFLAGS = ' -O3 -DNDEBUG'
-- USING LDFLAGS = ' '
== Detect external libraries ==
== Detect external libraries (DONE) ==
== Generating build files ==
Configuring libCGAL
-- Found GMP: /usr/lib/x86_64-linux-gnu/libgmp.a
-- Found MPFR: /usr/lib/x86_64-linux-gnu/libmpfr.a
-- Found Boost: /usr/include (found suitable version "1.65.1", minimum required is "1.48")
-- Boost include dirs: /usr/include
-- Boost libraries:
-- Using gcc version 4 or later. Adding -frounding-math
-- USING GMP_VERSION = '6.1.2'
-- USING MPFR_VERSION = '4.0.1'
-- USING BOOST_VERSION = '1.65.1'
libCGAL is configured
-- Sources for CGAL component library 'CGAL_Core' detected
Configuring libCGAL_Core
libCGAL_Core is configured
-- Sources for CGAL component library 'CGAL_ImageIO' detected
Configuring libCGAL_ImageIO
-- Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found version "1.2.11")
-- USING ZLIB_VERSION = '1.2.11'
libCGAL_ImageIO is configured
-- Sources for CGAL component library 'CGAL_Qt5' detected
Configuring libCGAL_Qt5
-- libCGAL_Qt5 is missing the dependencies: Qt5Svg Qt5 cannot be configured.
-- Sources for CGAL component libraries 'CGAL_Core;CGAL_ImageIO;CGAL_Qt5' detected
== Generating build files (DONE) ==
-- Configuring done
-- Generating done
-- Build files have been written to: /home/adminlocal/PhD/cpp/cgal-5.1.1/build
My code:
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- cmake location: /usr/local
-- used compiler: GNU
-- used compiler version: 7.5.0
-- Build type not specified, using Debug
-- Found GCO
-- Includes : /usr/local/include/gco-v3.0
-- Libraries : /usr/local/lib/libgco.a
-- Performing Test arch_native_supported
-- Performing Test arch_native_supported - Success
-- Eigen 3.3.4 found (include: /usr/include/eigen3)
-- Found OpenMP_C: -fopenmp (found version "4.5")
-- Found OpenMP_CXX: -fopenmp (found version "4.5")
-- Found OpenMP: TRUE (found version "4.5")
-- Enabling OpenMP support
-- Disabling CUDA support
-- Using header-only CGAL
-- Found GMP: /usr/lib/x86_64-linux-gnu/libgmp.a;/usr/lib/x86_64-linux-gnu/libgmpxx.a
-- Found MPFR: /usr/include (Required is at least version "1.0.0")
-- Found MPFR: /usr/lib/x86_64-linux-gnu/libmpfr.a
-- Found Boost: /usr/include (found suitable version "1.65.1", minimum required is "1.48")
-- Boost include dirs: /usr/include
-- Boost libraries:
-- Using gcc version 4 or later. Adding -frounding-math
-- Found CGAL 5.1.1
-- Includes : /usr/local/include
-- Libraries :
-- Found Boost: /usr/include (found version "1.65.1") found components: iostreams program_options system serialization filesystem regex
-- Configuring done
-- Generating done
-- Build files have been written to: /home/adminlocal/PhD/cpp/surfaceReconstruction/build/release
Of CGAL:
cmake .. -DCGAL_HEADER_ONLY=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Release -DMPFR_LIBRARIES=/usr/lib/x86_64-linux-gnu/libmpfr.a -DGMP_LIBRARIES=/usr/lib/x86_64-linux-gnu/libgmp.a -DGMPXX_LIBRARIES=/usr/lib/x86_64-linux-gnu/libgmpxx.a
That is the CMake command line. I would like you use make VERBOSE=1
so that make
displays the command lines it uses for the compiler. And I would like to see the linker command line that triggers the link error.
[ 96%] Building CXX object CMakeFiles/sure.dir/src/exe/sure.cpp.o
/usr/bin/c++ -DCGAL_USE_GMPXX=1 -DEIGEN_INITIALIZE_MATRICES_BY_NAN -DUNIX -I/home/adminlocal/PhD/cpp/surfaceReconstruction/src -I/home/adminlocal/PhD/cpp/surfaceReconstruction/external -I/usr/include/eigen3 -I/usr/local/include/gco-v3.0 -g -O3 -Wno-deprecated-declarations -Wno-unused-result -Wno-all -Wno-attributes -Wno-enum-compare -Wno-delete-incomplete -frounding-math -fopenmp -o CMakeFiles/sure.dir/src/exe/sure.cpp.o -c /home/adminlocal/PhD/cpp/surfaceReconstruction/src/exe/sure.cpp
[100%] Linking CXX executable sure
/usr/local/bin/cmake -E cmake_link_script CMakeFiles/sure.dir/link.txt --verbose=1
/usr/bin/c++ -g -static CMakeFiles/sure.dir/src/exe/sure.cpp.o CMakeFiles/sure.dir/src/exe/inputParser.cpp.o -o sure libfileIO.a liblearning.a librPLY.a libutil.a libprocessing.a /usr/lib/x86_64-linux-gnu/libboost_iostreams.a /usr/lib/x86_64-linux-gnu/libboost_program_options.a /usr/lib/x86_64-linux-gnu/libboost_system.a /usr/lib/x86_64-linux-gnu/libboost_serialization.a /usr/lib/x86_64-linux-gnu/libboost_filesystem.a /usr/lib/x86_64-linux-gnu/libboost_regex.a -ldl /usr/local/lib/libgco.a /usr/lib/x86_64-linux-gnu/libgmp.a /usr/lib/x86_64-linux-gnu/libgmpxx.a /usr/lib/x86_64-linux-gnu/libgmpxx.a /usr/lib/x86_64-linux-gnu/libmpfr.a /usr/lib/gcc/x86_64-linux-gnu/7/libgomp.a /usr/lib/x86_64-linux-gnu/libdl.a /usr/lib/x86_64-linux-gnu/libpthread.a /usr/lib/x86_64-linux-gnu/libz.a
/usr/lib/x86_64-linux-gnu/libmpfr.a(mpfr-gmp.o): In function `mpfr_tmp_allocate':
(.text+0x3b): undefined reference to `__gmp_get_memory_functions'
(.text+0x54): undefined reference to `__gmp_get_memory_functions'
/usr/lib/x86_64-linux-gnu/libmpfr.a(mpfr-gmp.o): In function `mpfr_tmp_free':
(.text+0xe9): undefined reference to `__gmp_get_memory_functions'
(.text+0x105): undefined reference to `__gmp_get_memory_functions'
/usr/lib/x86_64-linux-gnu/libmpfr.a(mpfr-gmp.o): In function `mpfr_allocate_func':
(.text.hot+0x26): undefined reference to `__gmp_get_memory_functions'
/usr/lib/x86_64-linux-gnu/libmpfr.a(mpfr-gmp.o):(.text.hot+0x7f): more undefined references to `__gmp_get_memory_functions' follow
/usr/lib/x86_64-linux-gnu/libmpfr.a(div.o): In function `mpfr_div':
(.text.hot+0x2e1): undefined reference to `__gmpn_divrem'
(.text.hot+0x551): undefined reference to `__gmpz_sizeinbase'
(.text.hot+0x58d): undefined reference to `__gmpz_sizeinbase'
(.text.hot+0x5d4): undefined reference to `__gmpz_tdiv_q'
(.text.hot+0x5e1): undefined reference to `__gmpz_sizeinbase'
(.text.hot+0x601): undefined reference to `__gmpz_scan1'
(.text.hot+0x644): undefined reference to `__gmpz_scan0'
(.text.hot+0x137f): undefined reference to `__gmpz_mul_2exp'
/usr/lib/x86_64-linux-gnu/libmpfr.a(pool.o): In function `mpfr_free_pool':
(.text+0x33): undefined reference to `__gmpz_clear'
/usr/lib/x86_64-linux-gnu/libmpfr.a(pool.o): In function `mpfr_mpz_init':
(.text.hot+0x39): undefined reference to `__gmpz_init'
/usr/lib/x86_64-linux-gnu/libmpfr.a(pool.o): In function `mpfr_mpz_init2':
(.text.hot+0x81): undefined reference to `__gmpz_init2'
/usr/lib/x86_64-linux-gnu/libmpfr.a(pool.o): In function `mpfr_mpz_clear':
(.text.hot+0xc9): undefined reference to `__gmpz_clear'
/usr/lib/x86_64-linux-gnu/libmpfr.a(round_prec.o): In function `mpfr_round_raw':
(.text+0x426): undefined reference to `__gmpn_copyd'
/usr/lib/x86_64-linux-gnu/libmpfr.a(round_prec.o): In function `mpfr_round_raw_4':
(.text+0xd3d): undefined reference to `__gmpn_copyd'
/usr/lib/x86_64-linux-gnu/libmpfr.a(round_prec.o): In function `mpfr_prec_round':
(.text+0x1776): undefined reference to `__gmpn_copyd'
/usr/lib/x86_64-linux-gnu/libmpfr.a(get_z_exp.o): In function `mpfr_get_z_2exp':
(.text+0x45): undefined reference to `__gmpz_realloc2'
(.text+0xaf): undefined reference to `__gmpz_set_ui'
/usr/lib/x86_64-linux-gnu/libmpfr.a(mulders.o): In function `mpfr_divhigh_n':
(.text+0x49d): undefined reference to `__gmpn_divrem'
(.text+0x85e): undefined reference to `__gmpn_divrem'
collect2: error: ld returned 1 exit status
CMakeFiles/sure.dir/build.make:137: recipe for target 'sure' failed
make[2]: *** [sure] Error 1
make[2]: Leaving directory '/home/adminlocal/PhD/cpp/surfaceReconstruction/build/release'
CMakeFiles/Makefile2:243: recipe for target 'CMakeFiles/sure.dir/all' failed
make[1]: *** [CMakeFiles/sure.dir/all] Error 2
make[1]: Leaving directory '/home/adminlocal/PhD/cpp/surfaceReconstruction/build/release'
Makefile:102: recipe for target 'all' failed
make: *** [all] Error 2
@raphaelsulzer In my opinion you issue is not related to the subject of this issue.
Earlier in the discussion, https://github.com/CGAL/cgal/issues/2466#issuecomment-768257442, you pasted:
-- Using header-only CGAL
-- Found GMP: /usr/lib/x86_64-linux-gnu/libgmp.a;/usr/lib/x86_64-linux-gnu/libgmpxx.a
-- Found MPFR: /usr/include (Required is at least version "1.0.0")
-- Found MPFR: /usr/lib/x86_64-linux-gnu/libmpfr.a
-- Found Boost: /usr/include (found suitable version "1.65.1", minimum required is "1.48")
-- Boost include dirs: /usr/include
-- Boost libraries:
-- Using gcc version 4 or later. Adding -frounding-math
-- Found CGAL 5.1.1
and I do not really understand what CMake code displayed that, in particulat the part about MPFR:
-- Found MPFR: /usr/include (Required is at least version "1.0.0")
What would require version "1.0.0" for MPFR? I doubt the CMake code comes from CGAL.
You are right! It was coming from a FindMPFR.cmake which I had accidentally included.
Everything works now.
Thank you very much for helping me tracking it down.
Hello
Issue Details
I am using the CGAL library as a third part component of a library. To compile my executables in static mode (no shared library), I need to build CGAL in static mode
I am building CGAL in header-only mode and I do the following :
cmake . -DCGAL_HEADER_ONLY=ON -DBUILD_SHARED_LIBS=OFF
However, the configuration links to the libraries libmpfr.so and libgmp.so rather than libmpfr.a and libgmp.a
I can work around by setting in addition the path to the libraries :
cmake . -DCGAL_HEADER_ONLY=ON -DBUILD_SHARED_LIBS=OFF -DMPFR_LIBRARIES=/use<path/to/libmpfr.a> -DGMP_LIBRARIES=<path/to/libgmp.a>
Environment
Thank you, Tom.