在DLL中包含OpenVDB;将错误与Visual Studio 2015链接

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在DLL中包含OpenVDB;将错误与Visual Studio 2015链接相关的知识,希望对你有一定的参考价值。

我试图在Visual Studio 2015中编译一个我正在制作的DLL,它充当了与OpenVDB的某些功能相关的C兼容包装器,使其可以在现有的C项目中使用。但是,当我构建时,我得到以下链接器错误:

Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: class std::shared_ptr<class std::basic_streambuf<char,struct std::char_traits<char> > > __thiscall openvdb::v4_0_1::io::MappedFile::createBuffer(void)const " (__imp_?createBuffer@MappedFile@io@v4_0_1@openvdb@@QBE?AV?$shared_ptr@V?$basic_streambuf@DU?$char_traits@D@std@@@std@@@std@@XZ) referenced in function "private: void __thiscall openvdb::v4_0_1::tree::LeafBuffer<float,3>::doLoad(void)const " (?doLoad@?$LeafBuffer@M$02@tree@v4_0_1@openvdb@@ABEXXZ)

Error   LNK2019 unresolved external symbol "__declspec(dllimport) class std::shared_ptr<class openvdb::v4_0_1::io::StreamMetadata> __cdecl openvdb::v4_0_1::io::getStreamMetadataPtr(class std::ios_base &)" (__imp_?getStreamMetadataPtr@io@v4_0_1@openvdb@@YA?AV?$shared_ptr@VStreamMetadata@io@v4_0_1@openvdb@@@std@@AAVios_base@5@@Z) referenced in function "void __cdecl openvdb::v4_0_1::io::readCompressedValues<float,class openvdb::v4_0_1::util::NodeMask<3> >(class std::basic_istream<char,struct std::char_traits<char> > &,float *,unsigned int,class openvdb::v4_0_1::util::NodeMask<3> const &,bool)" (??$readCompressedValues@MV?$NodeMask@$02@util@v4_0_1@openvdb@@@io@v4_0_1@openvdb@@YAXAAV?$basic_istream@DU?$char_traits@D@std@@@std@@PAMIABV?$NodeMask@$02@util@12@_N@Z)

Error   LNK2019 unresolved external symbol "__declspec(dllimport) void __cdecl openvdb::v4_0_1::io::setStreamMetadataPtr(class std::ios_base &,class std::shared_ptr<class openvdb::v4_0_1::io::StreamMetadata> &,bool)" (__imp_?setStreamMetadataPtr@io@v4_0_1@openvdb@@YAXAAVios_base@std@@AAV?$shared_ptr@VStreamMetadata@io@v4_0_1@openvdb@@@5@_N@Z) referenced in function "private: void __thiscall openvdb::v4_0_1::tree::LeafBuffer<float,3>::doLoad(void)const " (?doLoad@?$LeafBuffer@M$02@tree@v4_0_1@openvdb@@ABEXXZ)

Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: static class std::shared_ptr<class openvdb::v4_0_1::math::Transform> __cdecl openvdb::v4_0_1::math::Transform::createLinearTransform(class openvdb::v4_0_1::math::Mat4<double> const &)" (__imp_?createLinearTransform@Transform@math@v4_0_1@openvdb@@SA?AV?$shared_ptr@VTransform@math@v4_0_1@openvdb@@@std@@ABV?$Mat4@N@234@@Z) referenced in function "public: static class std::shared_ptr<class openvdb::v4_0_1::math::Transform> __cdecl OpenVDB_c::LinearTransform(double,double,double,double,double,double,double,double,double,double,double,double,double,double,double,double)" (?LinearTransform@OpenVDB_c@@SA?AV?$shared_ptr@VTransform@math@v4_0_1@openvdb@@@std@@NNNNNNNNNNNNNNNN@Z)

Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: void __thiscall openvdb::v4_0_1::GridBase::setTransform(class std::shared_ptr<class openvdb::v4_0_1::math::Transform>)" (__imp_?setTransform@GridBase@v4_0_1@openvdb@@QAEXV?$shared_ptr@VTransform@math@v4_0_1@openvdb@@@std@@@Z) referenced in function __catch$?setGridTransform@OpenVDB_c@@QAE_NHV?$shared_ptr@VTransform@math@v4_0_1@openvdb@@@std@@@Z$0

Error   LNK2019 unresolved external symbol "__declspec(dllimport) public: class std::shared_ptr<class openvdb::v4_0_1::GridBase> __thiscall openvdb::v4_0_1::io::File::readGrid(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_?readGrid@File@io@v4_0_1@openvdb@@QAE?AV?$shared_ptr@VGridBase@v4_0_1@openvdb@@@std@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@6@@Z) referenced in function "public: int __thiscall OpenVDB_c::readGrid(int,char *)" (?readGrid@OpenVDB_c@@QAEHHPAD@Z)

Error   LNK2001 unresolved external symbol "public: virtual class std::shared_ptr<class openvdb::v4_0_1::io::Archive> __thiscall openvdb::v4_0_1::io::File::copy(void)const " (?copy@File@io@v4_0_1@openvdb@@UBE?AV?$shared_ptr@VArchive@io@v4_0_1@openvdb@@@std@@XZ)

Error   LNK2001 unresolved external symbol "public: virtual void __thiscall openvdb::v4_0_1::io::File::write(class std::vector<class std::shared_ptr<class openvdb::v4_0_1::GridBase const >,class std::allocator<class std::shared_ptr<class openvdb::v4_0_1::GridBase const > > > const &,class openvdb::v4_0_1::MetaMap const &)const " (?write@File@io@v4_0_1@openvdb@@UBEXABV?$vector@V?$shared_ptr@$$CBVGridBase@v4_0_1@openvdb@@@std@@V?$allocator@V?$shared_ptr@$$CBVGridBase@v4_0_1@openvdb@@@std@@@2@@std@@ABVMetaMap@34@@Z)

Error   LNK2001 unresolved external symbol "__declspec(dllimport) private: static union half::uif const * const half::_toFloat" (__imp_?_toFloat@half@@0QBTuif@1@B) C:Users	00001657documentsvisual studio 2015ProjectsOVDBCOVDBCovdbc.obj  1

OpenVDB及其所有依赖项都在include文件夹中,其目录被添加到其他include目录中,这是我目前Linker选项下的Additional Dependencies列表:

  • blosc.lib
  • cppunit.lib
  • glew32.lib
  • glfw3.lib
  • Half.lib
  • 法是,2_2.lib
  • IexMath-2_2.lib
  • IlmImf-2_2.lib
  • IlmImfUtil-2_2.lib
  • IlmThread-2_2.lib
  • Imath2_2.lib
  • openvdb.lib
  • tbb.lib
  • tbb_debug.lib
  • tbb_preview.lib
  • tbb_preview_debug.lib
  • tbbmalloc.lib
  • tbbmalloc_debug.lib
  • tbbproxy.lib
  • zlibstaticd.lib

我似乎无法在Visual Studio中找到有关使用OpenVDB进行编译的任何信息来涵盖这种错误,而且我很难忘记我可能会忘记的内容。

答案

结果证明是两个问题的组合:

  1. 我的OpenVDB二进制文件是使用定义的OPENVDB_3_ABI_COMPATIBLE编译的,因此使用了boost版本的shared_ptr而不是std版本,但是在尝试构建我的项目时我没有定义OPENVDB_3_ABI_COMPATIBLE,因此它尝试使用std版本进行构建;因此,未定义的外部。
  2. 我没有定义OPENEXR_DLL和HALF_EXPORTS,这在构建这些库时显然是必需的,我不知道。
  3. 我正在使用/ MT选项进行编译,而不是使用half.lib使用的/ MDd选项

最后,我需要做的就是定义OPENEXR_DLL,HALF_EXPORTS和OPENVDB_3_ABI_COMPATIBLE,并将构建选项切换为/ MDd。

另一答案

尝试使用Vcpkg。

它支持视觉工作室2015,2017

https://github.com/Microsoft/vcpkg

它在Linux中像yum一样易于使用。

以上是关于在DLL中包含OpenVDB;将错误与Visual Studio 2015链接的主要内容,如果未能解决你的问题,请参考以下文章

如何在 Visual Studio C++ 的 dll 项目中包含一个库

在 Visual C++ DLL 中包含 MFC 资源(CDialog-Form)

Visual Studio 2012 上的计算机错误中缺少 GDAL201.dll

尝试在 Visual Studio 2012 中包含 OpenSSL 标头:错误 LNK2019:未解析的外部符号

不能在 Visual Studio 中包含 Python.h

无法在 Visual Studio 2013 中包含文件