osg第三方库的编译笔记-collada,jpeg

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


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章