Windows下編譯Collada
因爲collada的模型是基於xml的在網絡傳輸中使用比較好,其中谷歌地球中使用的模型都是這種格式的,若想在本機上讀入dae格式數據就需要這個庫支持。
下載好支撐庫:
pcre、libxml2、zlib、boost;確保這些庫都正確編譯過去
在動態編譯的時候導出的靜態成員沒有在調用這個類的實現文件裏面聲明就會產生如下的錯誤:
1>daeURI.obj : error LNK2001: unresolved external symbol "public: static class pcrecpp::Arg pcrecpp::RE::no_arg" (?no_arg@RE@pcrecpp@@2VArg@2@A)
daeURI.cpp中添加這麼一句就沒有問題了,
pcrecpp::Arg pcrecpp::RE::no_arg((void*)NULL);
這個解決方案指標不治本,根本的原因在於靜態鏈接版本需要添加PCRE_STATIC宏,然而動態版本的不需要,現在PCRE庫默認給動態版本和靜態版本都添加了這個宏(visual studio下查看preprocessor選項)過去默認的情況下是都不添加導致靜態庫出現問題,這是老版本的問題,解決方法是這樣的: You need the PCRE_STATIC preprocessor definition in your project.
至於爲什麼要添加這個宏可以看他下面的源碼:
#ifndef _PCRE_H
#define _PCRE_H
/* When an application links to a PCRE DLL in Windows, the symbols that are
imported have to be identified as such. When building PCRE, the appropriate
export setting is defined in pcre_internal.h, which includes this file. So we
don't change existing definitions of PCRE_EXP_DECL and PCRECPP_EXP_DECL. */
#if defined(_WIN32) && !defined(PCRE_STATIC)
# ifndef PCRE_EXP_DECL
# define PCRE_EXP_DECL extern __declspec(dllimport)
# endif
# ifdef __cplusplus
# ifndef PCRECPP_EXP_DECL
# define PCRECPP_EXP_DECL extern __declspec(dllimport)
# endif
# ifndef PCRECPP_EXP_DEFN
# define PCRECPP_EXP_DEFN __declspec(dllimport)
# endif
# endif
#endif
/* By default, we use the standard "extern" declarations. */
#ifndef PCRE_EXP_DECL
# ifdef __cplusplus
# define PCRE_EXP_DECL extern "C"
# else
# define PCRE_EXP_DECL extern
# endif
#endif
#ifdef __cplusplus
# ifndef PCRECPP_EXP_DECL
# define PCRECPP_EXP_DECL extern
# endif
# ifndef PCRECPP_EXP_DEFN
# define PCRECPP_EXP_DEFN
# endif
#endif
據說靜態庫編譯時,用到osg的時候編譯通不過,我想一定程度上跟這個有關。
collada插件報錯
Error: Failed to open in daeLIBXMLPlugin::readFromFile
Error: Failed to load
Load failed in COLLADA DOM
Load failed in COLLADA DOM conversion
osgviewerd.exe: No data loaded
導致這個問題的根源在於文件路徑無法真確解析成URI故libxml無法取到指定的數據。
當然造成讀取不了數據的原因有很多種,比如數據格式不符、文件路徑不對、文件內部結果錯誤,在我的案例裏是由於文件路徑不正確導致的。
google了一下在這裏有一個帖子討論了相關問題,據說是libxml2出了問題。具體還待查。
靜態編譯jpeg轉爲動態編譯
新建一個空白的動態鏈接庫工程(.dll工程)並命名爲 jpegdll。把 jpeg工程 中的源文件和頭文件設置複製到 jpegdll 中
接下來從 DLL 中導出接口。打開 jmorecfg.h,把 GLOBAL 的定義改成:
#define GLOBAL(type) __declspec(dllexport) type
把 EXTERN 的定義改成:
#define EXTERN(type) extern __declspec(dllexport) type