如何在CLion / Linux项目中包含CGAL [英] How to include CGAL in CLion/Linux Project

查看:160
本文介绍了如何在CLion / Linux项目中包含CGAL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对C ++ Cmake和Clion还是比较陌生,我一直在努力为在Clion(我在Ubuntu Gnome上运行)下的项目安装CGAL。我在这里或其他地方都找不到类似的问题,已经被封锁了一个多星期,所以我将不胜感激。

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.

我安装了CGAL Cmake GUI,运行进行安装。在Clion中使用以下CMakeList.txt:

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})

这是main.cpp:

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;
}

Clion可以识别CGAL,因为我可以在外部图书馆/标头搜索路径,以及自动补全标识CGAL元素,例如此处Nef_polyhedron_3.h。然而,有了这个简单的未使用的include语句,我从事件日志和Messages Build Window输出中获得了 .ms生成失败消息:

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

查看了时间间隔nt.h:208,我可以看到以下代码摘录:

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)?");
}

这就是为什么我在CMakeLists.txt中添加-frounding-math的原因(没有成功)。在构建CGAL时,我还检查了CMAKE_CXX_FALGS在Cmake中是否为-frounding-math(参见图片)。

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捕获CGAL构建CMAKE CXX标记-frounding-math

这是按照Marc的建议使VERBOSE = 1 输出:

/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

,这是当在以下位置使用VERBOSE制作项目:

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*, 

M arc建议该问题来自错误显示函数 CGAL :: assertion_fail 不能说明的库的错误链接。确实-lCGAL标志不可见,这是问题所在吗?

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 ?

推荐答案

问题来自不正确的CMakeList.txt文件。这是一个有效的版本。感谢@MarcGlisse的帮助:

The problem came from incorrect CMakeList.txt file. Here is a version that works. Thanks @MarcGlisse for your help :

cmake_minimum_required(VERSION 3.5)
project(AGRAN)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
find_package(CGAL REQUIRED)
include(${CGAL_USE_FILE})

set(SOURCE_FILES main.cpp)
add_executable(AGRAN ${SOURCE_FILES})
target_link_libraries(AGRAN ${CGAL_LIBS})

这篇关于如何在CLion / Linux项目中包含CGAL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆