I'm relatively new to C++ Cmake and Clion and I've been struggling with installing CGAL for my project under Clion (which I run on Ubuntu Gnome). I could not find similar issues here or elsewhere and have been blocked for over a week now so I'd greatly appreciate some help.
I installed CGAL Cmake GUI, run the make and the install. With the following CMakeList.txt in Clion :
cmake_minimum_required(VERSION 3.5)
project(AGRAN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -frounding-math")
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
set(LIBS ${LIBS} ${OpenCV_LIBRARIES})
find_package(CGAL REQUIRED COMPONENTS Core GMP RS3 MPFI )
include_directories(${CGAL_INCLUDE_DIRS})
set(LIBS ${LIBS} ${CGAL_LIBRARIES})
find_package( Boost REQUIRED )
include_directories(${Boost_INCLUDE_DIRS})
set(LIBS ${LIBS} ${Boost_LIBRARIES})
set(SOURCE_FILES main.cpp)
add_executable(AGRAN ${SOURCE_FILES})
target_link_libraries(AGRAN ${LIBS})
and here is the main.cpp :
#include <iostream>
#include <CGAL/Nef_polyhedron_3.h>
using namespace std;
int main() {
cout << "Hello, World!" << endl;
return 0;
}
CGAL is reckognized by Clion as I can see its files in the External Libraries/Header Search Paths, and as autocompletion identifies CGAL elements such as here Nef_polyhedron_3.h. Yet with this simple unused include statement I get "Build failed in ...ms" from the Event log and the Messages Build Window outputs :
/home/jeremie/CMake/cmake-3.5.2-Linux-x86_64/bin/cmake --build/home/jeremie/.CLion2016.1/system/cmake/generated/AGRAN-39898ace/39898ace/Debug0 --target AGRAN -- -j 8
[ 50%] Building CXX object CMakeFiles/AGRAN.dir/main.cpp.o
CMakeFiles/AGRAN.dir/main.cpp.o: In function `CGAL::Interval_nt<false>::Test_runtime_rounding_modes::Test_runtime_rounding_modes()':
/usr/local/include/CGAL/Interval_nt.h:208: undefined reference to `CGAL::assertion_fail(char const*, char const*, int, char const*)'
/usr/local/include/CGAL/Interval_nt.h:210
Having looked at the Interval nt.h:208 I could see the following code extract :
typename Interval_nt<>::Internal_protector P;
CGAL_assertion_msg(-CGAL_IA_MUL(-1.1, 10.1) != CGAL_IA_MUL(1.1, 10.1),
"Wrong rounding: did you forget the -frounding-math option if you use GCC (or -fp-model strict for Intel)?");
CGAL_assertion_msg(-CGAL_IA_DIV(-1., 10) != CGAL_IA_DIV(1., 10),
"Wrong rounding: did you forget the -frounding-math option if you use GCC (or -fp-model strict for Intel)?");
}
Which is why I added -frounding-math to CMakeLists.txt (without success). I also checked that the CMAKE_CXX_FALGS was -frounding-math in Cmake when building CGAL (see image).
CMAKE CAPTURE CGAL BUILD CMAKE CXX FLAGS -frounding-math
Here is the make VERBOSE=1
output as suggested by Marc :
/home/jeremie/CMake/cmake-3.5.2-Linux-x86_64/bin/cmake -H/home/jeremie/CLibraries/CGAL-4.8 -B/home/jeremie/CLibraries/CGAL-4.8/build --check-build-system CMakeFiles/Makefile.cmake 0
/home/jeremie/CMake/cmake-3.5.2-Linux-x86_64/bin/cmake -E cmake_progress_start /home/jeremie/CLibraries/CGAL-4.8/build/CMakeFiles /home/jeremie/CLibraries/CGAL-4.8/build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/jeremie/CLibraries/CGAL-4.8/build'
make -f src/CGAL/CMakeFiles/CGAL.dir/build.make src/CGAL/CMakeFiles/CGAL.dir/depend
make[2]: Entering directory '/home/jeremie/CLibraries/CGAL-4.8/build'
cd /home/jeremie/CLibraries/CGAL-4.8/build && /home/jeremie/CMake/cmake-3.5.2-Linux-x86_64/bin/cmake -E cmake_depends "Unix Makefiles" /home/jeremie/CLibraries/CGAL-4.8 /home/jeremie/CLibraries/CGAL-4.8/src/CGAL /home/jeremie/CLibraries/CGAL-4.8/build /home/jeremie/CLibraries/CGAL-4.8/build/src/CGAL /home/jeremie/CLibraries/CGAL-4.8/build/src/CGAL/CMakeFiles/CGAL.dir/DependInfo.cmake --color=
Dependee "/home/jeremie/CLibraries/CGAL-4.8/build/src/CGAL/CMakeFiles/CGAL.dir/DependInfo.cmake" is newer than depender "/home/jeremie/CLibraries/CGAL-4.8/build/src/CGAL/CMakeFiles/CGAL.dir/depend.internal".
Dependee "/home/jeremie/CLibraries/CGAL-4.8/build/src/CGAL/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "/home/jeremie/CLibraries/CGAL-4.8/build/src/CGAL/CMakeFiles/CGAL.dir/depend.internal".
Scanning dependencies of target CGAL
make[2]: Leaving directory '/home/jeremie/CLibraries/CGAL-4.8/build'
make -f src/CGAL/CMakeFiles/CGAL.dir/build.make src/CGAL/CMakeFiles/CGAL.dir/build
make[2]: Entering directory '/home/jeremie/CLibraries/CGAL-4.8/build'
[ 16%] Building CXX object src/CGAL/CMakeFiles/CGAL.dir/all_files.cpp.o
cd /home/jeremie/CLibraries/CGAL-4.8/build/src/CGAL && /usr/bin/c++ -DCGAL_EXPORTS -DCGAL_USE_GMP -DCGAL_USE_MPFR -I/home/jeremie/CLibraries/CGAL-4.8/build/include -I/home/jeremie/CLibraries/CGAL-4.8/include -isystem /usr/include/x86_64-linux-gnu -frounding-math -O3 -DNDEBUG -fPIC -o CMakeFiles/CGAL.dir/all_files.cpp.o -c /home/jeremie/CLibraries/CGAL-4.8/build/src/CGAL/all_files.cpp
[ 33%] Linking CXX shared library ../../lib/libCGAL.so
cd /home/jeremie/CLibraries/CGAL-4.8/build/src/CGAL && /home/jeremie/CMake/cmake-3.5.2-Linux-x86_64/bin/cmake -E cmake_link_script CMakeFiles/CGAL.dir/link.txt --verbose=1
/usr/bin/c++ -fPIC -frounding-math -O3 -DNDEBUG -shared -Wl,-soname,libCGAL.so.11 -o ../../lib/libCGAL.so.11.0.2 CMakeFiles/CGAL.dir/all_files.cpp.o -lmpfr -lgmp -lboost_thread -lboost_system -lboost_chrono -lboost_date_time -lboost_atomic
cd /home/jeremie/CLibraries/CGAL-4.8/build/src/CGAL && /home/jeremie/CMake/cmake-3.5.2-Linux-x86_64/bin/cmake -E cmake_symlink_library ../../lib/libCGAL.so.11.0.2 ../../lib/libCGAL.so.11 ../../lib/libCGAL.so
make[2]: Leaving directory '/home/jeremie/CLibraries/CGAL-4.8/build'
[ 33%] Built target CGAL
make -f src/CGAL_Core/CMakeFiles/CGAL_Core.dir/build.make src/CGAL_Core/CMakeFiles/CGAL_Core.dir/depend
make[2]: Entering directory '/home/jeremie/CLibraries/CGAL-4.8/build'
cd /home/jeremie/CLibraries/CGAL-4.8/build && /home/jeremie/CMake/cmake-3.5.2-Linux-x86_64/bin/cmake -E cmake_depends "Unix Makefiles" /home/jeremie/CLibraries/CGAL-4.8 /home/jeremie/CLibraries/CGAL-4.8/src/CGAL_Core /home/jeremie/CLibraries/CGAL-4.8/build /home/jeremie/CLibraries/CGAL-4.8/build/src/CGAL_Core /home/jeremie/CLibraries/CGAL-4.8/build/src/CGAL_Core/CMakeFiles/CGAL_Core.dir/DependInfo.cmake --color=
Dependee "/home/jeremie/CLibraries/CGAL-4.8/build/src/CGAL_Core/CMakeFiles/CGAL_Core.dir/DependInfo.cmake" is newer than depender "/home/jeremie/CLibraries/CGAL-4.8/build/src/CGAL_Core/CMakeFiles/CGAL_Core.dir/depend.internal".
Dependee "/home/jeremie/CLibraries/CGAL-4.8/build/src/CGAL_Core/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "/home/jeremie/CLibraries/CGAL-4.8/build/src/CGAL_Core/CMakeFiles/CGAL_Core.dir/depend.internal".
Scanning dependencies of target CGAL_Core
make[2]: Leaving directory '/home/jeremie/CLibraries/CGAL-4.8/build'
make -f src/CGAL_Core/CMakeFiles/CGAL_Core.dir/build.make src/CGAL_Core/CMakeFiles/CGAL_Core.dir/build
make[2]: Entering directory '/home/jeremie/CLibraries/CGAL-4.8/build'
[ 50%] Building CXX object src/CGAL_Core/CMakeFiles/CGAL_Core.dir/all_files.cpp.o
cd /home/jeremie/CLibraries/CGAL-4.8/build/src/CGAL_Core && /usr/bin/c++ -DCGAL_Core_EXPORTS -DCGAL_USE_GMP -DCGAL_USE_MPFR -I/home/jeremie/CLibraries/CGAL-4.8/build/include -I/home/jeremie/CLibraries/CGAL-4.8/include -isystem /usr/include/x86_64-linux-gnu -frounding-math -O3 -DNDEBUG -fPIC -o CMakeFiles/CGAL_Core.dir/all_files.cpp.o -c /home/jeremie/CLibraries/CGAL-4.8/build/src/CGAL_Core/all_files.cpp
[ 66%] Linking CXX shared library ../../lib/libCGAL_Core.so
cd /home/jeremie/CLibraries/CGAL-4.8/build/src/CGAL_Core && /home/jeremie/CMake/cmake-3.5.2-Linux-x86_64/bin/cmake -E cmake_link_script CMakeFiles/CGAL_Core.dir/link.txt --verbose=1
/usr/bin/c++ -fPIC -frounding-math -O3 -DNDEBUG -shared -Wl,-soname,libCGAL_Core.so.11 -o ../../lib/libCGAL_Core.so.11.0.2 CMakeFiles/CGAL_Core.dir/all_files.cpp.o -L/home/jeremie/CLibraries/CGAL-4.8/build/lib -lmpfr -lgmp ../../lib/libCGAL.so.11.0.2 -lboost_thread -lboost_system -lboost_chrono -lboost_date_time -lboost_atomic -lmpfr -lgmp -lboost_thread -lboost_system -lboost_chrono -lboost_date_time -lboost_atomic -Wl,-rpath,/home/jeremie/CLibraries/CGAL-4.8/build/lib:
cd /home/jeremie/CLibraries/CGAL-4.8/build/src/CGAL_Core && /home/jeremie/CMake/cmake-3.5.2-Linux-x86_64/bin/cmake -E cmake_symlink_library ../../lib/libCGAL_Core.so.11.0.2 ../../lib/libCGAL_Core.so.11 ../../lib/libCGAL_Core.so
make[2]: Leaving directory '/home/jeremie/CLibraries/CGAL-4.8/build'
[ 66%] Built target CGAL_Core
make -f src/CGAL_ImageIO/CMakeFiles/CGAL_ImageIO.dir/build.make src/CGAL_ImageIO/CMakeFiles/CGAL_ImageIO.dir/depend
make[2]: Entering directory '/home/jeremie/CLibraries/CGAL-4.8/build'
cd /home/jeremie/CLibraries/CGAL-4.8/build && /home/jeremie/CMake/cmake-3.5.2-Linux-x86_64/bin/cmake -E cmake_depends "Unix Makefiles" /home/jeremie/CLibraries/CGAL-4.8 /home/jeremie/CLibraries/CGAL-4.8/src/CGAL_ImageIO /home/jeremie/CLibraries/CGAL-4.8/build /home/jeremie/CLibraries/CGAL-4.8/build/src/CGAL_ImageIO /home/jeremie/CLibraries/CGAL-4.8/build/src/CGAL_ImageIO/CMakeFiles/CGAL_ImageIO.dir/DependInfo.cmake --color=
Dependee "/home/jeremie/CLibraries/CGAL-4.8/build/src/CGAL_ImageIO/CMakeFiles/CGAL_ImageIO.dir/DependInfo.cmake" is newer than depender "/home/jeremie/CLibraries/CGAL-4.8/build/src/CGAL_ImageIO/CMakeFiles/CGAL_ImageIO.dir/depend.internal".
Dependee "/home/jeremie/CLibraries/CGAL-4.8/build/src/CGAL_ImageIO/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "/home/jeremie/CLibraries/CGAL-4.8/build/src/CGAL_ImageIO/CMakeFiles/CGAL_ImageIO.dir/depend.internal".
Scanning dependencies of target CGAL_ImageIO
make[2]: Leaving directory '/home/jeremie/CLibraries/CGAL-4.8/build'
make -f src/CGAL_ImageIO/CMakeFiles/CGAL_ImageIO.dir/build.make src/CGAL_ImageIO/CMakeFiles/CGAL_ImageIO.dir/build
make[2]: Entering directory '/home/jeremie/CLibraries/CGAL-4.8/build'
[ 83%] Building CXX object src/CGAL_ImageIO/CMakeFiles/CGAL_ImageIO.dir/all_files.cpp.o
cd /home/jeremie/CLibraries/CGAL-4.8/build/src/CGAL_ImageIO && /usr/bin/c++ -DCGAL_ImageIO_EXPORTS -DCGAL_USE_GMP -DCGAL_USE_MPFR -DCGAL_USE_ZLIB -I/home/jeremie/CLibraries/CGAL-4.8/build/include -I/home/jeremie/CLibraries/CGAL-4.8/include -isystem /usr/include/x86_64-linux-gnu -isystem /home/jeremie/CLibraries/CGAL-4.8/src/CGAL_ImageIO/. -frounding-math -O3 -DNDEBUG -fPIC -o CMakeFiles/CGAL_ImageIO.dir/all_files.cpp.o -c /home/jeremie/CLibraries/CGAL-4.8/build/src/CGAL_ImageIO/all_files.cpp
[100%] Linking CXX shared library ../../lib/libCGAL_ImageIO.so
cd /home/jeremie/CLibraries/CGAL-4.8/build/src/CGAL_ImageIO && /home/jeremie/CMake/cmake-3.5.2-Linux-x86_64/bin/cmake -E cmake_link_script CMakeFiles/CGAL_ImageIO.dir/link.txt --verbose=1
/usr/bin/c++ -fPIC -frounding-math -O3 -DNDEBUG -shared -Wl,-soname,libCGAL_ImageIO.so.11 -o ../../lib/libCGAL_ImageIO.so.11.0.2 CMakeFiles/CGAL_ImageIO.dir/all_files.cpp.o -L/home/jeremie/CLibraries/CGAL-4.8/build/lib -lmpfr -lgmp ../../lib/libCGAL.so.11.0.2 -lboost_thread -lboost_system -lboost_chrono -lboost_date_time -lboost_atomic -lGLU -lGL -lz -lmpfr -lgmp -lboost_thread -lboost_system -lboost_chrono -lboost_date_time -lboost_atomic -Wl,-rpath,/home/jeremie/CLibraries/CGAL-4.8/build/lib:
cd /home/jeremie/CLibraries/CGAL-4.8/build/src/CGAL_ImageIO && /home/jeremie/CMake/cmake-3.5.2-Linux-x86_64/bin/cmake -E cmake_symlink_library ../../lib/libCGAL_ImageIO.so.11.0.2 ../../lib/libCGAL_ImageIO.so.11 ../../lib/libCGAL_ImageIO.so
make[2]: Leaving directory '/home/jeremie/CLibraries/CGAL-4.8/build'
[100%] Built target CGAL_ImageIO
make[1]: Leaving directory '/home/jeremie/CLibraries/CGAL-4.8/build'
/home/jeremie/CMake/cmake-3.5.2-Linux-x86_64/bin/cmake -E cmake_progress_start /home/jeremie/CLibraries/CGAL-4.8/build/CMakeFiles 0
and here is the output when making the project with VERBOSE on :
/home/jeremie/CMake/cmake-3.5.2-Linux-x86_64/bin/cmake --build /home/jeremie/.CLion2016.1/system/cmake/generated/AGRAN-39898ace/39898ace/Debug0 --target AGRAN -- -j 8
/home/jeremie/CMake/cmake-3.5.2-Linux-x86_64/bin/cmake -H/home/jeremie/ClionProjects/AGRAN -B/home/jeremie/.CLion2016.1/system/cmake/generated/AGRAN-39898ace/39898ace/Debug0 --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/make -f CMakeFiles/Makefile2 AGRAN
make[1]: Entering directory '/home/jeremie/.CLion2016.1/system/cmake/generated/AGRAN-39898ace/39898ace/Debug0'
/home/jeremie/CMake/cmake-3.5.2-Linux-x86_64/bin/cmake -H/home/jeremie/ClionProjects/AGRAN -B/home/jeremie/.CLion2016.1/system/cmake/generated/AGRAN-39898ace/39898ace/Debug0 --check-build-system CMakeFiles/Makefile.cmake 0
/home/jeremie/CMake/cmake-3.5.2-Linux-x86_64/bin/cmake -E cmake_progress_start /home/jeremie/.CLion2016.1/system/cmake/generated/AGRAN-39898ace/39898ace/Debug0/CMakeFiles 2
/usr/bin/make -f CMakeFiles/Makefile2 CMakeFiles/AGRAN.dir/all
make[2]: Entering directory '/home/jeremie/.CLion2016.1/system/cmake/generated/AGRAN-39898ace/39898ace/Debug0'
/usr/bin/make -f CMakeFiles/AGRAN.dir/build.make CMakeFiles/AGRAN.dir/depend
make[3]: Entering directory '/home/jeremie/.CLion2016.1/system/cmake/generated/AGRAN-39898ace/39898ace/Debug0'
cd /home/jeremie/.CLion2016.1/system/cmake/generated/AGRAN-39898ace/39898ace/Debug0 && /home/jeremie/CMake/cmake-3.5.2-Linux-x86_64/bin/cmake -E cmake_depends "Unix Makefiles" /home/jeremie/ClionProjects/AGRAN /home/jeremie/ClionProjects/AGRAN /home/jeremie/.CLion2016.1/system/cmake/generated/AGRAN-39898ace/39898ace/Debug0 /home/jeremie/.CLion2016.1/system/cmake/generated/AGRAN-39898ace/39898ace/Debug0 /home/jeremie/.CLion2016.1/system/cmake/generated/AGRAN-39898ace/39898ace/Debug0/CMakeFiles/AGRAN.dir/DependInfo.cmake --color=
make[3]: Leaving directory '/home/jeremie/.CLion2016.1/system/cmake/generated/AGRAN-39898ace/39898ace/Debug0'
/usr/bin/make -f CMakeFiles/AGRAN.dir/build.make CMakeFiles/AGRAN.dir/build
make[3]: Entering directory '/home/jeremie/.CLion2016.1/system/cmake/generated/AGRAN-39898ace/39898ace/Debug0'
[ 50%] Linking CXX executable AGRAN
/home/jeremie/CMake/cmake-3.5.2-Linux-x86_64/bin/cmake -E cmake_link_script CMakeFiles/AGRAN.dir/link.txt --verbose=1
/usr/bin/c++ -std=c++11 -frounding-math -g CMakeFiles/AGRAN.dir/main.cpp.o -o AGRAN /usr/local/lib/libopencv_videostab.so.3.1.0 /usr/local/lib/libopencv_superres.so.3.1.0 /usr/local/lib/libopencv_stitching.so.3.1.0 /usr/local/lib/libopencv_shape.so.3.1.0 /usr/local/lib/libopencv_photo.so.3.1.0 /usr/local/lib/libopencv_objdetect.so.3.1.0 /usr/local/lib/libopencv_calib3d.so.3.1.0 /usr/local/lib/libopencv_features2d.so.3.1.0 /usr/local/lib/libopencv_ml.so.3.1.0 /usr/local/lib/libopencv_highgui.so.3.1.0 /usr/local/lib/libopencv_videoio.so.3.1.0 /usr/local/lib/libopencv_imgcodecs.so.3.1.0 /usr/local/lib/libopencv_flann.so.3.1.0 /usr/local/lib/libopencv_video.so.3.1.0 /usr/local/lib/libopencv_imgproc.so.3.1.0 /usr/local/lib/libopencv_core.so.3.1.0 -Wl,-rpath,/usr/local/lib
CMakeFiles/AGRAN.dir/main.cpp.o: In function `CGAL::Interval_nt<false>::Test_runtime_rounding_modes::Test_runtime_rounding_modes()':
/usr/local/include/CGAL/Interval_nt.h:208: undefined reference to `CGAL::assertion_fail(char const*,
Marc suggested the problem comes from incorrect linking of the library illustrated by the error revealing function CGAL::assertion_fail
is unreachable. Indeed the -lCGAL flag is not visible, would it be the problem ? what should be changed to correct this ?