2
votes

I'm getting strange (for me) errors during compiling a test program which uses some parts of the CGAL library.

First, the environment:

  • Windows 7 64 bits
  • Boost 1.53
  • CGAL 4.3
  • Qt 4.8.4
  • CMake 2.8.10.2
  • Visual Studio 2010 professional
  • I installed all the libraries for 32 bits (if this was an option during installation).

Installation wrong?

In order to install CGAL on my computer, I followed this tutorial: http://www.cgal.org/windows_installation.html. I have to note here that this did not work out-of-the-box for me. During the configuration phase of CGAL in CMake, the boost libraries were not found (although I set the corresponding environment variables, as stated in the tutorial). After setting the incorrect variables in CMake, I was able to complete the configuration and generation phase. After that, I was able to compile both the Debug as well as the Release configurations of CGAL in Visual Studio.

In order to test whether the CGAL lib was installed successfully, I tried to compile and run both the examples and demos. These also did not work immediately. The problem was that the CGAL and Boost headers (and binaries) were not found. After setting the right paths in Project properties => Configuration properties => C/C++ => Additional Include Directories and in Project properties => Configuration properties => Linker => Additional Library Directories the examples and demos could be build. I successfully ran these examples after that.

Actual problem

Now, I'm tyring to compile a simple program, in order to be able to make a certain exercise (http://acg.cs.tau.ac.il/courses/algorithmic-robotics/spring-2013/exercises/assignment-2 exercise 2.1). Here, there are two files supplied: basic_typdef.h and 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;
}

(For convenience I removed the comments in the file cgal_bootcamp.cpp)

With Visual Studio, I can compile the two files as above. However, when I try to create a Point (as defined in basic_typedef.h), I'm getting the (strange) errors:

#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;
}

The errors that occur:

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   

I have no clue what is going wrong here (I have to note that I'm still a noob with C++). It seems that there is something wrong with the GMP library (at least the linking to this?) I found in another post that for someone there were no libgmp files build (can't find that post anymore), but that is not the case for me (I think): in CGAL-4.3/auxiliary/gmp/lib I see four files, libgmp-10.dll libgmp-10.lib libmpfr-4.dll and libmpfr-4.lib.

Also the error on line 4 points to something that might cause this error ("Mixing a dll CGAL library with a static runtime is a really bad idea..."), but I do not know what this actually means (or how I can resolve it).

Further, I tried to setup all the libraries on another computer, but I got the same errors there also.

Could anyone point me in the right direction to solve this problem? If you need more information, please let me know.

1
Did you create your vcproj file with cgal_create_cmake_script? I ask because I am wondering if the compiler knows where to look for the GMP library.Andreas Fabri
libgmp-10.lib does exist on your machine, but you should also configure your project to link with it, and with libmpfr-4.lib as well.lrineau
Thank you both for your reactions! After the comment of Andreas Fabri I realized that 'just' putting the source and header files in a newly created project (by the Visual Studio wizard) is not the right way. Now, I used the cgal_create_cmake_script on my source file to generate a Visual Studio project and this project builds without errors. Further, I can even debug the application. Thank you very much!user2246266
typedef Kernel::Point_2 Point; shouldn't compile (if it does, then only because the compiler offers this as a language extension). Correct is typedef typename Kernel::Point_2 Point;Walter

1 Answers

2
votes

This comment answered the question: the script cgal_create_cmake_script can be used to create a CMake file that can be used to generate a correct Visual Studio project using CGAL.