在Ubuntu 16.04上使用带有Eclipse的CGAL库

问题描述 投票:0回答:1

我试图在Eclipse Oxygen下使用CGAL库运行一些“Hello world”测试,但是我失败了十几个未定义的引用错误。

我按照建议的apt-driven installation method跑步

sudo apt-get install libcgal-dev
sudo apt-get install libcgal-demo

但现在我完全迷失了如何链接库并使Eclipse正确包含和使用CGAL。

这是我正在尝试构建的程序:

#include <iostream>
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <sstream>
typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
typedef Kernel::Point_2 Point_2;
int main()
{
  Point_2 p(0, 0.3), q, r(2, 0.9);
  {
    q  = Point_2(1, 0.6);
    std::cout << (CGAL::collinear(p,q,r) ? "collinear\n" : "not 
    collinear\n");
   }

   {
    std::istringstream input("0 0.3   1 0.6   2 0.9");
    input >> p >> q >> r;
    std::cout << (CGAL::collinear(p,q,r) ? "collinear\n" : "not 
    collinear\n");
    }

   {
    q = CGAL::midpoint(p,r);
    std::cout << (CGAL::collinear(p,q,r) ? "collinear\n" : "not 
    collinear\n");   
    }

    return 0;
  }

这是我收到的错误的一个例子:

make all 
Building target: exact
Invoking: Cross G++ Linker
g++ -L/usr/lib/x86_64-linux-gnu -L/usr/lib -o "exact"  ./exact.o   
./exact.o: In function `CGAL::Handle::Handle(CGAL::Handle const&)':
/usr/include/CGAL/Handle.h:55: undefined reference to 
`CGAL::precondition_fail(char const*, char const*, int, char const*)'
makefile:44: recipe for target 'exact' failed

我尝试在Cross G ++ Linker和Cross GCC编译器下包含GCAL库所在的目录,但无济于事。

不幸的是,我在C ++编程和Eclipse中都是初学者!

谢谢您的帮助!

c++ eclipse-cdt cgal
1个回答
0
投票

我经历了多次这样的痛苦。 :d

以下是我学到的课程*:

  1. 不要从ubuntu存储库下载cgal - 从他们的网站and build from source下载
  2. 确保安装了所有依赖项(boost等)
  3. 右键单击您的项目 - >属性 - > C / C ++生成 - >设置 - >工具设置。

在GCC C ++链接器下:

添加库CGAL,gmp,mpfr,boost_thread

设置库搜索路径:(您的路径)/CGAL-4.11.1/lib

在GCC C ++编译器下: - >包括:添加包含路径(yourpath)/CGAL-4.11.1/include/

现在试试。如果它仍然没有,因为您无法动态链接正确的文件,请在链接下的杂项下添加“-rpath /home/merlin/UbuntuSoftware/CGAL-4.11.1/lib”。

希望有所帮助。

梅林:)

© www.soinside.com 2019 - 2024. All rights reserved.