contour工程編譯

contour工程是基于計算機圖形學論文:

Computing Smooth Surface Contours with Accurate Topology.
Pierre Bénard, Aaron Hertzmann, Michael Kass. ACM Transactions on
Graphics, 2013

工程來自github:
http://github.com/benardp/contours

工程需要配置的依賴庫:

  • cmake * Qt 4.8 libraries (Freestyle) * libQGLViewer (Freestyle) * SWIG (Freestyle)

libQGLViewer編譯過程

參考:libQGLViewer的安裝配置與編譯

先從官網上下載libQGLViewer-2.6.4

然后選擇打開libQGLViewer-2.6.4文件夾下的libQGLViewer-2.6.4.pro文件(我已經安裝好了qt),然后點擊構建項目(ctl+B),然后報錯:
error: LNK1104: 無法打開文件“QGLViewerd2.lib”

放棄,然后在visual studio 中編譯。參照:
QGLViewer 編譯安裝步驟
打開visual studio 2013,點擊菜單欄QT5->Open Qt Project File,選擇步驟1 解壓的路徑\QGLViewer\QGLViewer.pro, 然后點擊生成解決方案。然后生成解決方案的時候,報錯:
LINK : fatal error LNK1104: 無法打開文件“GLU.lib”
估計是把所有的項目一塊生成解決方案的問題,然后把右鍵QGLViewer單獨重新生成,成功生成動態庫文件。
生成的庫文件在目錄F:\Chen\download\libQGLViewer-2.6.4\QGLViewer下面。

接著就把生成的兩個dll文件拷到響應的目錄下面。
C:\Windows\System32

SWIG的編譯

SWIG是C++和C語言與腳本語言的連接。在這個程序中,主要就是將C++語言中使用python的腳本語言。

所以,先安裝一下python(這個大家應該都裝好了,可以現在命令行里面輸入python看看自己安裝的是哪一個版本)。

我先安裝一下python3.3.3,然后輸入命令行python沒反應,重啟一下命令行就好了。然后輸入print ('Hello World!')
成功運行。
然后按照SWIG文檔的說明,把包含Python.h的文件夾D:\python\include添加到PYTHON_INCLUDE
把D:\python\libs\python33.lib添加到PYTHON_LIB,python.lib有兩個,是python3.lib和phthon33.lib,我不知道添加哪個,就隨便用一下后面這個吧,出了問題再說

PYTHON_INCLUDE : Set this to the directory that contains Python.h
PYTHON_LIB : Set this to the python library including path for linking

Example using Python 2.1.1:
PYTHON_INCLUDE: D:\python21\include
PYTHON_LIB: D:\python21\libs\python21.lib

到這里,我打開python文件夾下面的example文件夾下的dsp文件就自動生成項目,然后把項目改成x64平臺上,就能找到源代碼。我要編譯的項目用camke來完成項目的編譯,然后用SWIG來鏈接python。那我還是深切懷疑到底能不能成功運行。然后查了一下官方文檔,大概是這么說的:

SWIG是一個命令行工具,可以集成到可以調用外部工具和編譯器的系統中,SWIG可以在Makefile文件中被調用,也可以被像Visual Studio一樣的IDE中被調用。

一些構建項目的工具也開始支持SWIG如camke,cmake可以檢測到SWIG的可執行文件和對應語言的鏈接庫,在許多不同的操作系統中,cmake知道怎么構建共享庫和可加載的模塊

swig hellow world!

先把下載的swig文件夾下面的swig.exe加入到環境變量path中,我把D:\chen\download\swigwin-3.0.10加入到path中,然后輸入swig到命令行工具里面,顯示:
Must specify an input file. Use -help for available options.

將官網上的案例程序example.cpp,example.h,example.i放到一個文件夾中。

example.h

/* example.h */
#ifndef EXAMPLE_H
#define EXAMPLE_H
//void cHelloWorld();
int compute(int a, int b);
#endif

example.cpp

/* example.cpp */
#include <iostream>
#include "example.h"
using namespace std;

int compute(int a, int b)
{
    int temp = (a+b)*(a-b);
    return temp;
}

example.i(swig接口文件)

/* File : example.i */
%module example

%inline %{
#include "example.h"
%}
int compute(int a,int b);

然后輸入命令:cd /d D:\chen\mytest,改變命令行中的文件夾。
輸入命令:
swig -c++ -python example.i
生成example_wrap.cxx和example.py兩個文件。

camke

visual studio 的版本和VC版本的對應關系:
VC6.0對應VS 6.0
VC7.0對應VS 2002
VC7.1對應VS 2003
VC8.0對應VS 2005
VC9.0對應VS 2008
VC10對應VS 2010
VC11對應VS 2012
VC12對應VS 2013
在camke中選擇
Generates Visual Studio 12 (VS 2013) project files.

configure
因為我用的是qt5,但是項目使用qt4,所以需要進行一些修改:
詳見qt4升級到qt5需要干的那些事

然后繼續配置,報錯
1、找不到GLEW,把GLEW_INCLUDE_DIR和GLEW_LIBRARY填上然后基本解決。我因為編譯的是64位,所以lib文件也是glew64.lib,不知道放32位的會怎么樣,盡量匹配吧。而且文件路徑里面有空格貌似也沒有什么關系。只要CMake的安裝路徑里面沒有空格就行了。

報錯:
如果你的CMake報錯:
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:108 (message):
Could NOT find GLEW (missing: GLEW_INCLUDE_DIR GLEW_LIBRARY)
Call Stack (most recent call first):
C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:315 (_FPHSA_FAILURE_MESSAGE)
C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindGLEW.cmake:27 (find_package_handle_standard_args)
tess_RifFilter/opensubdiv/CMakeLists.txt:295 (find_package)

CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
GLEW_LIBRARY (ADVANCED)

2、安裝上了3Delight,然后給3Dlight_INCLUDE_DIR和3Delight_LIBRARY填上了值。
參考3Delight Studio Pro配置教程

然后把QGLViewerd2.lib、QGLViewer2.lib的文件路徑填上去,QGLVIEWER_LIBRARY_DEBUG和QGLVIEWER_LIBRARY_RELEASE都是同一個文件路徑。然后就把F:/Chen/download/libQGLViewer-2.6.4/QGLViewer填在兩個環境變量里面。

報錯:
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
3Delight_INCLUDE_DIR
used as include directory in directory D:/chen/download/contours-master/tess_RifFilter
3Delight_LIBRARIES
linked by target "tess_RifFilter" in directory D:/chen/download/contours-master/tess_RifFilter
QGLVIEWER_LIBRARY_RELEASE
linked by target "app" in directory D:/chen/download/contours-master/freestyle/app

最后,Cmake里面顯示:
Using cmake version 2.8.12
Could NOT find TBB (missing: TBB_INCLUDE_DIR TBB_LIBRARIES) (Required is at least version "4.0")
Could NOT find GLFW (missing: GLFW_INCLUDE_DIR GLFW_LIBRARIES) (Required is at least version "2.7.0")
Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE) (Required is at least version "1.8.4")
Could NOT find Docutils (missing: RST2HTML_EXECUTABLE) (Required is at least version "0.6")
CMake Warning at tess_RifFilter/opensubdiv/CMakeLists.txt:332 (message):
TBB was not found : support for TBB parallel compute kernels will be
diabled in Osd. If your compiler supports TBB directives, please refer to
the FindTBB.cmake shared module in your cmake installation.

Configuring done

就配置好了,有很多變量沒有找到,但是沒有關系。

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容