【发布时间】:2014-01-03 01:46:00
【问题描述】:
在编译使用 CGAL 库的某些部分的测试程序时,我遇到了奇怪的(对我而言)错误。
一、环境:
- Windows 7 64 位
- 提升 1.53
- CGAL 4.3
- Qt 4.8.4
- CMake 2.8.10.2
- Visual Studio 2010 专业版
- 我安装了所有 32 位的库(如果这是安装期间的一个选项)。
安装错误?
为了在我的电脑上安装 CGAL,我遵循了这个教程:http://www.cgal.org/windows_installation.html。我必须在这里指出,这对我来说不是开箱即用的。在 CMake 中配置 CGAL 的阶段,没有找到 boost 库(尽管我设置了相应的环境变量,如教程中所述)。在 CMake 中设置错误的变量后,我能够完成配置和生成阶段。之后,我能够在 Visual Studio 中编译 CGAL 的 Debug 和 Release 配置。
为了测试CGAL lib是否安装成功,我尝试编译运行examples和demo。这些也没有立即起作用。问题是没有找到 CGAL 和 Boost 头文件(和二进制文件)。在 Project properties => Configuration properties => C/C++ => Additional Include Directories 和 Project properties => Configuration properties => Linker => Additional Library Directories 中设置正确路径后 em> 可以构建示例和演示。之后我成功运行了这些示例。
实际问题
现在,我很想编译一个简单的程序,以便能够进行某个练习(http://acg.cs.tau.ac.il/courses/algorithmic-robotics/spring-2013/exercises/assignment-2练习 2.1)。这里提供了两个文件:basic_typdef.h 和 cgal_bootcamp.cpp
*basic_typedef.h*
#pragma once
#include <CGAL/Cartesian.h>
#include <CGAL/Gmpq.h>
#include <CGAL/Polygon_2.h>
#include <CGAL/Polygon_with_holes_2.h>
#include <CGAL/Boolean_set_operations_2/Gps_default_dcel.h>
#include <CGAL/Polygon_set_2.h>
#include <list>
/*******************************************************************************************
* This file contatins basic typedefs (from CGAL and more).
*******************************************************************************************/
typedef CGAL::Gmpq Number_type;
typedef CGAL::Cartesian<Number_type> Kernel;
typedef Kernel::Point_2 Point;
typedef CGAL::Polygon_2<Kernel> Polygon;
typedef CGAL::Polygon_with_holes_2<Kernel> Polygon_with_holes;
typedef CGAL::Polygon_set_2<Kernel> Polygon_set;
typedef std::list<Polygon_with_holes> Polygon_with_holes_container;
*cgal_bootcamp.cpp*
#include "basic_typedef.h"
int main(int argc, char* argv[])
{
return 0;
}
(为方便起见,我删除了文件 cgal_bootcamp.cpp 中的 cmets)
使用 Visual Studio,我可以像上面那样编译这两个文件。但是,当我尝试创建一个点(在 basic_typedef.h 中定义)时,我得到了(奇怪的)错误:
#include "basic_typedef.h"
int main(int argc, char* argv[])
{
/*
1. Point
http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Kernel_23_ref/Class_Point_2.html
*/
// Create Point with the coordinates (0.5, 0.6)
Point p;
return 0;
}
发生的错误:
Error 1 error LNK2019: unresolved external symbol __imp____gmpq_init referenced in function "public: __thiscall CGAL::Gmpq_rep::Gmpq_rep(void)" (??0Gmpq_rep@CGAL@@QAE@XZ) C:\Dropbox\Capita Selecta\Assignments\Assignment 2.1\warmup-exercise\cgal_bootcamp.obj warmup-exercise
Error 2 error LNK2019: unresolved external symbol __imp____gmpq_clear referenced in function "public: __thiscall CGAL::Gmpq_rep::~Gmpq_rep(void)" (??1Gmpq_rep@CGAL@@QAE@XZ) C:\Dropbox\Capita Selecta\Assignments\Assignment 2.1\warmup-exercise\cgal_bootcamp.obj warmup-exercise
Error 3 error LNK1120: 2 unresolved externals C:\Dropbox\Capita Selecta\Assignments\Assignment 2.1\warmup-exercise\Debug\warmup-exercise.exe 1 1 warmup-exercise
4 IntelliSense: #error directive: "Mixing a dll CGAL library with a static runtime is a really bad idea..." c:\dev\cgal-4.3\include\cgal\auto_link\auto_link.h 364 4
5 IntelliSense: #error directive: "some required macros where not defined (internal logic error)." c:\dev\cgal-4.3\include\cgal\auto_link\auto_link.h 397 4
我不知道这里出了什么问题(我必须注意我仍然是 C++ 的菜鸟)。 GMP库似乎有问题(至少链接到这个?)我在另一篇文章中发现对于某人来说没有构建libgmp文件(再也找不到那个帖子了),但事实并非如此对我来说(我认为):在 CGAL-4.3/auxiliary/gmp/lib 我看到四个文件,libgmp-10.dll libgmp-10.lib libmpfr-4.dll 和 libmpfr-4.lib。
此外,第 4 行的错误指出了可能导致此错误的原因(“将 dll CGAL 库与静态运行时混合是一个非常糟糕的主意......”),但我不知道这实际上意味着什么(或我该如何解决它)。
此外,我尝试在另一台计算机上设置所有库,但在那里也遇到了同样的错误。
谁能指出我解决这个问题的正确方向?如果您需要更多信息,请告诉我。
【问题讨论】:
-
您是否使用 cgal_create_cmake_script 创建了 vcproj 文件?我问是因为我想知道编译器是否知道在哪里寻找 GMP 库。
-
libgmp-10.lib 确实存在于您的计算机上,但您还应该配置您的项目以与其链接,以及与 libmpfr-4.lib 链接。
-
感谢两位的反应!在 Andreas Fabri 发表评论后,我意识到“只是”将源文件和头文件放在新创建的项目中(通过 Visual Studio 向导)不是正确的方法。现在,我在我的源文件中使用 cgal_create_cmake_script 生成了一个 Visual Studio 项目,并且该项目构建没有错误。此外,我什至可以调试应用程序。非常感谢!
-
typedef Kernel::Point_2 Point;不应该编译(如果编译,那只是因为编译器将其作为语言扩展提供)。正确的是typedef typename Kernel::Point_2 Point;
标签: c++ visual-studio-2010 cgal