背景
我对 C++ 和 CMake 比较陌生,尤其是对 CGAL 比较陌生。到目前为止,我只是想熟悉 CGAL,这样我就可以重新制作我最初在 MATLAB 中构建的算法,但是由于他们的计算几何库的不足,我正在转向 C++ 和 CGAL。
使用的系统和版本
操作系统内核:Ubuntu 20.04
CGAL 5.2.1
CMake 3.16.3
问题
我目前正在尝试构建“使用 Qt5 的最小示例”,发现 here .
起初,我收到一条错误消息,CGAL/Qt/Basic_viewer_qt.h: No such file or directory
.这似乎是一个简单的修复,因为 /usr/include/CGAL
中缺少 Qt 文件夹。目录,以及其他。在这里,CGAL 安装了 apt-get
.为了解决这个问题,我简单地复制了完整的 include
来自 CGAL 的 github 的目录。
现在,我仍然有一个问题来自 CMake,其中 CGAL_FOUND
返回 FALSE
当我尝试构建可执行文件时,我没有收到任何结果或错误消息(即 main
中没有 cgalTest/bin
可执行文件)。
更多详细信息
项目的文件夹结构
cgalTest
-bin
-build
--<CMake stuff>
-CMakeLists.txt
-doc
-include
-lib
-spike
-src
--main.cpp
-test
CMakeLists.txtcmake_minimum_required(VERSION 3.16.3)
project(cgalTest)
### Link with Libraries ###
# CGAL
find_package(CGAL REQUIRED COMPONENTS Qt5 Core)
if(CGAL_FOUND AND CGAL_Qt5_FOUND)
#required to use basic_viewer
add_definitions(-DCGAL_USE_BASIC_VIEWER -DQT_NO_KEYWORDS)
#create the executable of the application
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin)
add_executable(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp)
#link it with the required CGAL libraries
target_link_libraries(${PROJECT_NAME} CGAL::CGAL CGAL::CGAL_Qt5 CGAL::CGAL_Core)
else()
if(NOT CGAL_FOUND)
message("ERROR: this program requires CGAL and will not be compiled.")
endif()
if(NOT CGAL_Qt5_FOUND)
message("ERROR: this program requires CGAL_Qt5 and will not be compiled.")
endif()
endif()
主文件#include <iostream>
#include <string>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/draw_surface_mesh.h>
#include <fstream>
typedef CGAL::Simple_cartesian<double> Kernel;
typedef Kernel::Point_3 Point;
typedef CGAL::Surface_mesh<Point> Mesh;
using namespace std;
// Main Code
int main()
{
Mesh sm1;
std::ifstream in1((argc>1)?argv[1]:"data/elephant.off");
in1 >> sm1;
CGAL::draw(sm1);
return EXIT_SUCCESS;
}
我是如何构建项目的我只需运行以下命令:
cmake --build /home/<user>/Projects/cgalTest/build
CMake 配置输出[main] Configuring folder: cgalTest
[proc] Executing command: /usr/bin/cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -H/home/<user>/Projects/cgalTest -B/home/<user>/Projects/cgalTest/build -G "Unix Makefiles"
[cmake] Not searching for unused variables given on the command line.
[cmake] -- Using header-only CGAL
[cmake] -- Targetting Unix Makefiles
[cmake] -- Using /usr/bin/c++ compiler.
[cmake] -- Boost include dirs: /home/linuxbrew/.linuxbrew/include
[cmake] -- Boost libraries:
[cmake] -- Using gcc version 4 or later. Adding -frounding-math
[cmake] ERROR: this program requires CGAL_Qt5 and will not be compiled.
[cmake] CMake Warning at /home/linuxbrew/.linuxbrew/lib/cmake/CGAL/CGAL_enable_end_of_configuration_hook.cmake:99 (message):
[cmake] =======================================================================
[cmake]
[cmake] CGAL performance notice:
[cmake]
[cmake] The variable CMAKE_BUILD_TYPE is set to "Debug". For performance reasons,
[cmake] you should set CMAKE_BUILD_TYPE to "Release".
[cmake]
[cmake] Set CGAL_DO_NOT_WARN_ABOUT_CMAKE_BUILD_TYPE to TRUE if you want to disable
[cmake] this warning.
[cmake]
[cmake] =======================================================================
[cmake] Call Stack (most recent call first):
[cmake] CMakeLists.txt:9999 (CGAL_run_at_the_end_of_configuration)
[cmake]
[cmake]
[cmake] -- Configuring done
[cmake] -- Generating done
[cmake] -- Build files have been written to: /home/<user>/Projects/cgalTest/build
最后的想法正如我所说,我对此仍然很陌生,并且在其中一些过程中可能需要一些帮助。再次感谢,您的帮助将不胜感激。
此外,不要犹豫批评您看到的任何其他内容:文件夹结构、编码实践等
最佳答案
所以基本上,当我安装 qt5 时,我相信我使用过sudo apt-get libcal-qt5-default
而不是sudo apt-get libcal-qt5-dev
.
这当然是基于我对我在安装过程中所做的事情的内存,但只需运行“dev”的安装即可修复它(即,将 CGAL_QT_FOUND
设置为 TRUE
,然后让我编译)。
除此之外,在 main.cpp 中,我缺少 argc
的参数定义。和 argv
.
关于c++ - CGAL新手---入门难点: CGAL_Qt5 Returns FALSE in CMake,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67540342/