代码之家  ›  专栏  ›  技术社区  ›  Mutewinter

在Ubuntu 16.04上与Eclipse一起使用CGAL库

  •  0
  • Mutewinter  · 技术社区  · 6 年前

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

    我按照建议的 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
    

    我试图将GCAL库位于Eclipse中的目录包含在交叉G++链接器和交叉GCC编译器下,但没有成功。

    不幸的是,我对C++编程和Eclipse都是一个初学者!

    谢谢你的帮助!

    1 回复  |  直到 6 年前
        1
  •  0
  •   Merlin    6 年前

    我已经经历过多次了D

    以下是我学到的经验*:

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

    在GCC C++链接器下:

    添加库CGAL、gmp、mpfr、boost\u线程

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

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

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

    希望这有帮助。

    梅林:)