CGAL3.9+VS2010安装过程

安装了两天的程序不写点什么实在是对不起自己
The following section explains how to install CGAL 3.4 with Boost 1.38 with QT4.5 on Windows XP/Vista with Visual Studio 2008/2005
Note that during the entire setup you need internet connection!
【CGAL3.9+VS2010安装过程】Note that the installation requires significant disk space. Make sure to free enough disk space before the installation.
Instructions on adding Enviroment Variables in Windows are at the end.

  1. Downloading stuff
    1. First download CGAL (3.4) windows installer from here. (it is at the bottom of the page)
    2. Get the latest version of CMake (currently 2.6.3) from here.
    3. Download the latest version of QT framework (currently 4.6.3) from here.
    4. Download the latest version of Boost (currently 1.42) from here OR the automated windows installer from here (I installed it by compiling myself but other people installed it with the installer with no problems). It seems that there are some problems with version 1.42 and VC 9: https://lists-sop.inria.fr/sympa/arc/cgal-discuss/2010-02/msg00147.html
  2. Install CMake
    1. Use the default configuration and don't forget to add C:\Program Files\CMake
      2.6\bin to the PATH (if it wasn't added for you)
  3. Install Boost
There are several options/configurations for installing boost. The minimal requirements for CGAL will be added soon. In the meantime, if in doubt, perform a full install.
    1. If you downloaded the installer just install boost and continue to the next section otherwise continue to step 2. Don't forget to choose the boost_thread components for the Visual Studio version you have downloaded/installed when you use the installer.
    2. Create a directory c:\boost and copy boost_1_38_0.7z into it.
    3. Extract the Boost files to the C:\boost\boost_1_38_0 directory (right-click the file, go to 7zip and press extract here. If you don't have 7zip download and install from here)
    4. Don't delete boost_1_38_0.7z file after you are done extracting!!!
    5. open cmd (Strart->Run->cmd) and do : cd c:\boost\boost_1_38_0
    6. in the cmd type cmake-gui .( <-- this dot is important!!!)
    7. Create a new Visual Studio 2008 Generator (or the generator that fits your version of VS) by pressing Configure
    8. Press "Add Entry" and create a boolean item called CMAKE_IS_EXPERIMENTAL and set the value to true
    9. Press "configure"
    10. Select "Build Static" if it not yet selected (infact you should have all the BUILD_XXXXX flags set to true except from BUILD_TESTING)
    11. Click Configure until the Generate button becomes available
    12. Click Generate
    13. Close CMake. (here the dot is not important)
    14. Open the newly generated solution in the boost directory and press Build -> Clean Solution when this is done press Build -> Rebuild Solution
    15. Wait a long time.... If it asks you to save and restart visual studio using some sort of macro agree to it and let the macro finish.
    16. add C:\boost\boost_1_38_0\bin directory to the PATH
    17. Remeber I told you not to delete the 7zip file?
    18. Extract the Boost files to the C:\boost\boost_1_38_0 directory (right-click the file, go to 7zip and press extract here) tell it to overwrite all existing files. (In case you are having a de-ja-vu from step 2. You are right. For some unknown reason CMake destroys some of the files so you need to extract them all over again)
    19. Thats it Boost is installed.
Install QT
  1. Be warned! This installation took me 5 hours to complete so you might want to start it at the evening and leave it for the night.
  2. Run the QT installer executable (no, this is not the 5 hour part).
  3. Yes, you might need MinGW (not the source code) so download and install that to C:\MinGW. It is easiest to install directly through the QT installer. If you run into problems (with trolltech mirror), you can download the minGW installer seperately from sourceforge.net (currently version 5.1.4), install it, and then continue the QT installation, disregarding the warning message about version compatibility.
  4. once the installation of QT is finished Add C:\MinGW\bin to the path (if it wasnt done for you)
  5. If you open the lib directory of QT you will see it is filled with a bunch of files but non of them are lib files. So now lets create the lib files.
  6. Open Visual Studio Command Prompt (Start->Programs->Visual Studio->Visual Studio Tools->Visual Studio CommandPrompt) and write "cd c:\QT\4.5.0"
  7. in the black window write "configure"
  8. agree to the license and wait a while (still not 7 hours but I would go eat dinner about now)
  9. in the cmd window write "nmake" and go to sleep. This will take about 5 hours (at least on my old slow computer)
  10. Add C:\Qt\4.5.0\bin to the path
  11. Thats it QT is installed
  12. Restart your computer (don't forget to bookmark this page or something)
Install CGAL
  1. Finally we install the crown jewel. Run the installer and select your compiler and all the variants, next, next.
  2. I sugest installing CGAL to C:\CGAL\CGAL-3.4
  3. Tell the setup to create all the enviroment variables and wait for the install to complete. Including the downloads at the end.
  4. Add the enviroment variable QTDIR = C:\Qt\4.5.0
  5. Add the enviroment variable BOOST_ROOT = C:\boost\boost_1_38
  6. Open the command prompt (start->run->cmd)
  7. Type cd C:\CGAL\CGAL-3.4
  8. run cmake-gui . (<-- this dot is important again!)
  9. press configure and select your compiler
  10. If you have Cygwin installed (like me) the configure will fail becuase it was looking for the GMP and the MPFR code in the wrong place. Edit the GMP_INCLUDE_DIR and MPFR_INCLUDE_DIR to be C:/CGAL/CGAL-3.4/auxiliary/gmp/include
  11. Edit the CMAKE_BUILD_TYPE to Debug
  12. Select WITH_demos and WITH_examples if you wish the demos and the examples to be installed (although I don't see any reason to include those. You can just compile what you need when you need it).
  13. You may need to add the variable Boost_INCLUDE_DIR (=C:/boost/boost_1_38_0), and edit the variables Boost_THREAD_LIBRARY_DEBUG (=C:/boost/boost_1_38_0/lib/libboost_thread-vc90-mt-gd-1_38.lib) and Boost_THREAD_LIBRARY_RELEASE (= C:/boost/boost_1_38_0/lib/libboost_thread-vc90-mt-1_38.lib)
  14. Press Configure until you can press Generate and then press Generate
  15. A solution file will be created here : C:\CGAL\CGAL-3.4. Open it with your visual studio.
  16. Close CMAKE
  17. Press Build->Clean Solution, Press Build->Rebuild Solution. If you did everything I wrote before, including step 17 in the boost install the compile should work without problems (maybe some examples will not compile because you are missing 3rd party components but that isn't important).
  18. You are done! CGAL is installed.
At the end of the installation, your PATH should look something like that (this is my PATH) :
PATH=C:\Windows\system32; C:\Windows; C:\Windows\System32\Wbem;
C:\Program Files\ATI Technologies\ATI.ACE\Core-Static; c:\Program Files\Microsoft
SQL Server\90\Tools\binn\; C:\cygwin\bin; C:\cygwin\usr\bin; C:\cygwin\usr\local\b
in; C:\cygwin\usr\X11R6\bin; C:\gs\gs8.63\bin; C:\gs\gs8.63\lib; C:\boost\boost_1_38
_0\bin; C:\cygwin\usr\include; C:\MinGW\bin; C:\Qt\4.5.0\bin; C:\Program Files\CMake
2.6\bin; C:\CGAL\CGAL-3.4\auxiliary\gmp\lib
  1. Creating a Visual Studio Project that uses CGAL and QT
    1. Now that you have installed CGAL you need to configure your visual studio to work with it.
    2. Open an empty C++ project using the Win32 Console Application wizard (select empty project and click finish) File->New->Project... Other Languages -> C++ -> Win32 -> Win32 Console Application
    3. When the solution loads up go to Tools->Options ... Projects and Solutions -> VC++ Directories
      1. Make sure that Executable Files (Combobox at the top right)contains the $(PATH) variable (at the end there)
      2. Select Include Files in the combobox and add :
        1. C:\CGAL\CGAL-3.4\auxiliary\gmp\include
        2. C:\Qt\4.5.0\include
        3. C:\boost\boost_1_38_0
        4. C:\CGAL\CGAL-3.4\include
      3. They should appear at that order at the topmost part of the list (use the arrows to move items up and down)
      4. Select Library Files from the combobox and add :
        1. C:\CGAL\CGAL-3.4\auxiliary\gmp\lib
        2. C:\CGAL\CGAL-3.4\lib
        3. C:\boost\boost_1_38_0\lib
        4. C:\Qt\4.5.0\lib
      5. Press OK until you are back at the main window
      6. Right click your project and select Properties
      7. Go to Configuration Properties -> C/C++ -> General. In there you will see Additional Include Directories. Copy this line there :"C:\Qt\4.5.0\include\QtCore","C:\Qt\4.5.0\include\QtCore","C:\Qt\4.5.0\include\QtGui","C:\Qt\4.5.0\include\QtGui","C:\Qt\4.5.0\include","C:\Qt\4.5.0\include\ActiveQt","debug",".",C:\Qt\4.5.0\mkspecs\win32-msvc2005
      8. QT has a bunch of directories in their include so you need to add each directory individualy. The ones I write there should be enough for a beginner
      9. Go to Configuration Properties -> Linker -> Input and copy the following line to the Additional Dependancies line : C:\Qt\4.5.0\lib\qtmaind.lib C:\Qt\4.5.0\lib\QtGuid4.lib C:\Qt\4.5.0\lib\QtCored4.lib
      10. You will generaly need some of the libs as dependant files. The ones I gave above should be enoguh for a beginner program.
      11. Thats it, you can write your code and compile it here is an example of a main.cpp that should compile now :
----------------- CUT HERE ------------------
#include
#include
#include
#include
#include
#include
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QGraphicsScene scene;
scene.setSceneRect(0,0, 100, 100);
scene.addRect(QRectF(0,0, 100, 100), QPen(QColor(255,0,0)));
scene.addLine(QLineF(0,0, 100, 100));
scene.addLine(QLineF(0,100, 100, 0));
QGraphicsView* view = new QGraphicsView(&scene);
CGAL::Qt::GraphicsViewNavigation navigation;
view->installEventFilter(&navigation);
view->viewport()->installEventFilter(&navigation);
view->setRenderHint(QPainter::Antialiasing);
view->show();
return app.exec();
}
我装的是CGAL3.9,用的是CMake2.8,Boost也是最新的1.47,Qt4.8.0,VS2010成功(Win7系统),这里提示几点:
1、建议CGAL、CMake以及Boost都采用installer,也就是安装包版本,这样比较简单(链接下面都有,QT使用免费版的就OK)。
2、安装完成后,一定要按照要求把环境变量加入到系统的PATH下,我把必须的PATH贴出来:d:\CMake 2.8\bin; d:\Qt4.8.0\bin; E:\boost_1_47\bin; E:\CGAL-3.9\auxiliary\gmp\lib,另外好像还要加入BOOST_ROOT=E:\boost_1_47。(我一开始就是QT的路径没有添加,导致CMake一直报错,折腾了好久)
3、下面使用CMake的时候,工程输出路径直接采用的CGAL目录,要编译生成lib文件夹了才能用
4、如果CMake都过了的话,也就没什么大问题了。
5、按照要求,在VS2010的Include以及lib路径中,加入合适的路径就行了。这里VS2008和VS2010添加路径的地方有了点儿改变,VS2008在工具——选项——C++目录中,而VS2010需要在视图——属性管理器——项目下的Debug|Win32——Microsoft.Cpp.Win32.user——右键属性——C++目录中。
6、注意如果要编译下面提供的程序,还需要在项目属性中的连接器——输入——附加项中加入对应的.lib文件。
注意输入lib时要分行,不然VS识别不出。
即使这样还是出错了: main.cpp
1>CGAL_Qt4-vc100-mt-gd.lib(all_files.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl QGLFormat::~QGLFormat(void)" (__imp_??1QGLFormat@@ QEAA@XZ),referenced at "protected: void __cdecl CGAL::Qt::DemosMainWindow::setUseOpenGL(bool)" ( ?setUseOpenGL@DemosMainWindow@ Qt@CGAL@@ IEAAX_N@Z)1>CGAL_Qt4-vc100-mt-gd.lib(all_files.obj) : error LNK2019:unresolved external symbol "__declspec(dllimport) public: void __cdecl QGLWidget::setFormat(class QGLFormat const &)" ( __imp_?setFormat@QGLWidget@@QEAAXAEBVQGLFormat@@@Z),referenced in function"protected: void __cdecl CGAL::Qt::DemosMainWindow::setUseOpenGL(bool)" ( ?setUseOpenGL@DemosMainWindow@ Qt@CGAL@@ IEAAX_N@Z)1>CGAL_Qt4-vc100-mt-gd.lib(all_files.obj) : error LNK2019:unresolved external symbol "__declspec(dllimport) public: void __cdecl QGLFormat::setOption(class QFlags)" ( __imp_?setOption@QGLFormat@@ QEAAXV?$QFlags@W4FormatOption@QGL@@@@@Z),referenced in function"protected: void __cdecl CGAL::Qt::DemosMainWindow::setUseOpenGL(bool)" ( ?setUseOpenGL@DemosMainWindow@ Qt@CGAL@@ IEAAX_N@Z)1>CGAL_Qt4-vc100-mt-gd.lib(all_files.obj) : error LNK2019: unresolved external symbol"__declspec(dllimport) public: class QGLFormat __cdecl QGLWidget::format(void)const " ( __imp_?format@QGLWidget@@QEBA?AVQGLFormat@@XZ),referenced in function"protected: void __cdecl CGAL::Qt::DemosMainWindow::setUseOpenGL(bool)" ( ?setUseOpenGL@DemosMainWindow@ Qt@CGAL@@ IEAAX_N@Z)1>CGAL_Qt4-vc100-mt-gd.lib(all_files.obj) : error LNK2019: unresolved external symbol"__declspec(dllimport) public: __cdecl QGLWidget::QGLWidget(class QWidget *,class QGLWidget const *,class QFlags)" (__imp_??0QGLWidget@@ QEAA@PEAVQWidget@@ PEBV0@V?$QFlags@ W4WindowType@Qt@@@@@Z),referenced in function "protected: void __cdecl CGAL::Qt::DemosMainWindow::setUseOpenGL(bool)" ( ?setUseOpenGL@DemosMainWindow@ Qt@CGAL@@ IEAAX_N@Z)1>CGAL_Qt4-vc100-mt-gd.lib(all_files.obj) : error LNK2001: unresolved external symbol"public: virtual struct QMetaObject const * __cdecl QGLWidget::metaObject(void)const " ( ?metaObject@QGLWidget@@UEBAPEBUQMetaObject@@XZ) 1>CGAL_Qt4-vc100-mt-gd.lib(all_files.obj) : error LNK2001: unresolved external symbol"public: virtual void * __cdecl QGLWidget::qt_metacast(char const *)" ( ?qt_metacast@QGLWidget@@ UEAAPEAXPEBD@Z) 1>CGAL_Qt4-vc100-mt-gd.lib(all_files.obj) : error LNK2001: unresolved external symbol"public: virtual int __cdecl QGLWidget::qt_metacall(enum QMetaObject::Call,int,void * *)" ( ?qt_metacall@QGLWidget@@ UEAAHW4Call@QMetaObject@@ HPEAPEAX@Z) 1>CGAL_Qt4-vc100-mt-gd.lib(all_files.obj) : error LNK2001: unresolved external symbol "protected: virtual bool __cdecl QGLWidget::event(class QEvent *)" ( ?event@QGLWidget@@MEAA_NPEAVQEvent@@@Z) 1>CGAL_Qt4-vc100-mt-gd.lib(all_files.obj) : error LNK2001: unresolved external symbol"protected: virtual void __cdecl QGLWidget::paintEvent(class QPaintEvent *)" ( ?paintEvent@QGLWidget@@MEAAXPEAVQPaintEvent@@@Z) 1>CGAL_Qt4-vc100-mt-gd.lib(all_files.obj) : error LNK2001: unresolved external symbol"protected: virtual void __cdecl QGLWidget::resizeEvent(class QResizeEvent *)" ( ?resizeEvent@QGLWidget@@MEAAXPEAVQResizeEvent@@@Z) 1>CGAL_Qt4-vc100-mt-gd.lib(all_files.obj) : error LNK2001: unresolved external symbol "public: virtual void __cdecl QGLWidget::updateGL(void)" ( ?updateGL@QGLWidget@@UEAAXXZ) 1>CGAL_Qt4-vc100-mt-gd.lib(all_files.obj) : error LNK2001: unresolved external symbol"public: virtual void __cdecl QGLWidget::updateOverlayGL(void)" ( ?updateOverlayGL@QGLWidget@@UEAAXXZ) 1>CGAL_Qt4-vc100-mt-gd.lib(all_files.obj) : error LNK2001: unresolved external symbol"protected: virtual void __cdecl QGLWidget::initializeGL(void)" ( ?initializeGL@QGLWidget@@MEAAXXZ) 1>CGAL_Qt4-vc100-mt-gd.lib(all_files.obj) : error LNK2001: unresolved external symbol"protected: virtual void __cdecl QGLWidget::resizeGL(int,int)" ( ?resizeGL@QGLWidget@@ MEAAXHH@Z) 1>CGAL_Qt4-vc100-mt-gd.lib(all_files.obj) : error LNK2001: unresolved external symbol"protected: virtual void __cdecl QGLWidget::paintGL(void)" ( ?paintGL@QGLWidget@@MEAAXXZ) 1>CGAL_Qt4-vc100-mt-gd.lib(all_files.obj) : error LNK2001: unresolved external symbol"protected: virtual void __cdecl QGLWidget::initializeOverlayGL(void)" ( ?initializeOverlayGL@QGLWidget@@MEAAXXZ) 1>CGAL_Qt4-vc100-mt-gd.lib(all_files.obj) : error LNK2001: unresolved external symbol"protected: virtual void __cdecl QGLWidget::resizeOverlayGL(int,int)" ( ?resizeOverlayGL@QGLWidget@@ MEAAXHH@Z) 1>CGAL_Qt4-vc100-mt-gd.lib(all_files.obj) : error LNK2001: unresolved external symbol"protected: virtual void __cdecl QGLWidget::paintOverlayGL(void)" ( ?paintOverlayGL@QGLWidget@@MEAAXXZ) 1>CGAL_Qt4-vc100-mt-gd.lib(all_files.obj) : error LNK2001: unresolved external symbol"protected: virtual void __cdecl QGLWidget::glInit(void)" ( ?glInit@QGLWidget@@MEAAXXZ) 1>CGAL_Qt4-vc100-mt-gd.lib(all_files.obj) : error LNK2001: unresolved external symbol "protected: virtual void __cdecl QGLWidget::glDraw(void)" ( ?glDraw@QGLWidget@@MEAAXXZ) 1>CGAL_Qt4-vc100-mt-gd.lib(all_files.obj) : error LNK2001: unresolved external symbol"public: virtual class QPaintEngine * __cdecl QGLWidget::paintEngine(void)const " ( ?paintEngine@QGLWidget@@UEBAPEAVQPaintEngine@@XZ) 1>CGAL_Qt4-vc100-mt-gd.lib(all_files.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl QGLWidget::~QGLWidget(void)" (__imp_??1QGLWidget@@ UEAA@XZ),referenced in function"public: virtual void * __cdecl QGLWidget::`scalar deleting destructor'(unsigned int)" (??_GQGLWidget@@ UEAAPEAXI@Z) 中被引用 1>CGAL-vc100-mt-gd.lib(all_files.obj) : error LNK2019: unresolved external symbol__imp___gmpz_clear,referenced in function"public: __cdecl CORE::BigIntRep::~BigIntRep(void)" ( ??1BigIntRep@CORE@@ QEAA@XZ)1>D:\CGAL_TEST\cgal_test2\\cgal_test2.exe : fatal error LNK1120: 24 unresolved external commands 看来是少lib,解决方案:add C:\QT\4.8.0\lib\QtOpenGLd4.liband C:\CGAL-3.9\auxiliary\gmp\lib\libgmp-10.lib to the project 参见https://lists-sop.inria.fr/sympa/arc/cgal-discuss/2012-01/msg00186.html

    推荐阅读