c++ - 编译并运行CGAL Triangulation演示

标签 c++ g++ cgal

我正在尝试使用CGAL库显示2D Delaunay三角剖分,如示例here

我的代码如下所示:

#include <iostream>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Delaunay_triangulation_2.h>
#include <CGAL/draw_triangulation_2.h>

typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Delaunay_triangulation_2<K> Triangulation;
typedef Triangulation::Point Point;

int main(void){
    Point a(1,1), b(2,1), c(2,2), d(1,2);

    Triangulation T;
    T.insert(a);
    T.insert(b);
    T.insert(c);
    T.insert(d);

    CGAL::draw(T);

    return 0;
}

当我尝试使用g++ -o cgalTest.exe cgalTest.cpp -lCGAL -lgmp编译此代码时,程序成功编译,但是在运行时我得到了Impossible to draw because CGAL_USE_BASIC_VIEWER is not defined
通过在Google上搜索,我发现有人建议使用g++ -o cgalTest.exe cgalTest.cpp -lCGAL -lgmp -DCGAL_USE_BASIC_VIEWER,这会在编译时产生以下错误:/usr/include/CGAL/Qt/Basic_viewer_qt.h:30:10: fatal error: QApplication: No such file or directory #include <QApplication>
我正在使用ubuntu 19.04,因此我使用sudo apt-get install libcgal-devsudo apt-get install libcgal-qt5-dev安装了CGAl

我也尝试安装sudo apt-get install libqt5svg5-dev libqt5opengl5-dev来解决该错误,但无济于事。

我需要安装其他库吗?也许必须以不同的方式进行编译?

谢谢

最佳答案

好吧,对于任何面临相同问题的人,这是我解决的方法:

首先,我使用locate QApplication命令在系统上查找QApplication头文件的位置。使用sudo updatedb之前,请确保先运行locate。如果locate找不到QApplication的位置,则您缺少qt库。尝试sudo apt-get install qt5-default和我在问题中提到的其他库,运行sudo updatedb,然后再次尝试locate QApplication

当找到QApplication的路径时,只需使用-I选项来指示编译器使用它。这是一个g++ -o delaunayTest delaunayTest.cpp -lCGAL -lgmp -lCGAL_Qt5 -DCGAL_USE_BASIC_VIEWER -I/usr/include/x86_64-linux-gnu/qt5/QtWidgets/示例(因为在我的情况下,QApplication位于目录/usr/include/x86_64-linux-gnu/qt5/QtWidgets/内)

尝试与此编译,您可能会遇到另一个头文件错误。使用locate重复相同的过程,直到没有其他头文件错误为止。

届时,您可能会遇到undefined reference to symbol错误。

要解决此问题,请再次使用locate查找导致错误的文件的位置(例如libQt5OpenGL.so.5),并按原样将路径添加到编译命令(例如g++ -o delaunayTest delaunayTest.cpp /usr/lib/x86_64-linux-gnu/libQt5OpenGL.so.5)以及所有先前的选项。

您可能还会收到一些undefined reference to symbol错误。只是继续使用相同的方法,直到您一无所获。

此时,程序应正确编译并正确运行。

请注意,如果您安装了多个版本的qt,则上述方法可能无法正常工作(例如,如果您在系统中安装了使用qt的软件,例如MATLAB或anaconda,则会知道这是因为locate将为每个文件生成许多路径)以上步骤)。在这种情况下,我建议构建一个虚拟机,下载CGAL库和qt5-default并按照上面的步骤进行操作,因为这很可能在具有多个qt安装的系统中不起作用。

关于c++ - 编译并运行CGAL Triangulation演示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56581808/

相关文章:

c++ - 如何编辑和重新构建 GCC libstdc++ C++ 标准库源代码?

|| 的 C++ 排序and && 在 if 语句中测试相等性时

c++ - g++ 对 std::filesystem::last_write_time 的重大更改

c++ - 为什么 GCC 不允许我将模板参数用于另一个模板的参数?

c++ - 查找线段的交点和每个交点的相交线段列表

c++ - openMP 的目标和目标数据之间的区别?

c++ - 继承问题 : Using header files and default constructor of the base class in the derived class

g++ - gcc 警告" 'will be initialized after'

c++ - CGAL 三角剖分边迭代器包括原点

c++ - CGAL,限制在矩形中的裁剪 voronoi 图