我对C++Cmake和Clion还比较陌生,我一直在为Clion(我在Ubuntu Gnome上运行)下的项目安装CGAL。我在这里或其他地方找不到类似的问题,已经被屏蔽了一个多星期,所以我非常感谢你的帮助。
我安装了CGAL Cmake GUI,运行make和install。Clion中有以下CMakeList.txt:
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})
这是主.cpp:
#include <iostream>
#include <CGAL/Nef_polyhedron_3.h>
using namespace std;
int main() {
cout << "Hello, World!" << endl;
return 0;
}
CGAL被Clion识别,因为我可以在外部库/头搜索路径中看到它的文件,并且当自动完成识别CGAL元素时,例如这里的Nef_phylon_3.h。然而,通过这个简单的未使用的include语句,我从事件日志和消息构建窗口输出中得到"在…ms内构建失败":
/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之后,我可以看到以下代码摘录:
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数学(没有成功)。我还检查了CMAKE_CXX_FALGS在构建CGAL时在CMAKE中的数学基础(见图)。
CMAKE捕获CGAL构建CMAKE CXX FLAGS-从数学
以下是Marc:建议的make 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进行项目时的输出
/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表示,问题来自错误揭示函数CGAL::assertion_fail
不可访问所示的库的错误链接。确实-lCGAL标志不可见,这会是问题吗?应该做些什么来纠正这个问题?
问题来自错误的CMakeList.txt文件。这是一个有效的版本。感谢@MarcGlisse的帮助:
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})