c++ - 在 DLL 中包含 OpenVDB;与 Visual Studio 2015 的链接错误

标签 c++ visual-studio-2015 linker-errors unresolved-external openvdb

我正在尝试在 Visual Studio 2015 中编译一个我正在制作的 DLL,它充当 C 兼容的包装器,围绕 OpenVDB 的某些功能,使其可用于现有的 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\t00001657\documents\visual studio 2015\Projects\OVDBC\OVDBC\ovdbc.obj  1

OpenVDB 及其所有依赖项都在 include 文件夹中,其目录被添加到附加包含目录中,这是我当前在链接器选项下的附加依赖项列表:

  • blosc.lib
  • cppunit.lib
  • glew32.lib
  • glfw3.lib
  • Half.lib
  • Iex-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 的情况下编译的,因此使用的是 shared_ptr 的提升版本而不是标准版本,但是我在尝试构建我的项目时没有定义 OPENVDB_3_ABI_COMPATIBLE,因此它尝试使用 std 进行构建版本;因此,未定义的外部。
  2. 我没有定义 OPENEXR_DLL 和 HALF_EXPORTS,这在使用这些库构建时显然是必需的,但我不知道。
  3. 我使用/MT 选项而不是 half.lib 使用的/MDd 选项进行编译

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

关于c++ - 在 DLL 中包含 OpenVDB;与 Visual Studio 2015 的链接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44724454/

相关文章:

c++ - 使用 ffmpeg 无法解析的外部符号

visual-studio - MSVCRTD.lib(cpu_disp.obj) : warning LNK4210: . CRT 部分存在;可能存在未处理的静态初始值设定项或终止符

c++ - 仅使用 1 行 C++ 初始化二维 vector

c++ - 如何让 QML 容器中的最后一项填充剩余空间?

node.js - Azure/Node.js 未发生异常 : Error: Cannot find module 'ms'

visual-studio-2015 - 在 VS2015 Community Edition 中一行格式化属性

visual-studio-2015 - VS2015缺少未安装的框架(通用应用程序)

c++ - 什么是 undefined reference /未解析的外部符号错误,我该如何解决?

C++ OpenGL 创建发光线

c++ - 如何在鼠标左键按下时触发循环 autoclicker c++