Including OpenVDB in DLL; Linking errors with Visual Studio 2015

1.3k Views Asked by At

I am trying to compile, in Visual Studio 2015, a DLL that I am making which acts as a C-compatible wrapper around some functionality from OpenVDB, making it usable in an existing C project. When I build, however, I get the following Linker Errors:

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 and all of its dependencies are in the include folder, whose directory is added to additional include directories, and this is my current list of Additional Dependencies under the Linker options:

  • 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

I can't seem to find any information on compiling with OpenVDB in Visual Studio that covers this kind of error, and am pretty stumped as to what I could be forgetting.

2

There are 2 best solutions below

0
On BEST ANSWER

It turned out to be a combination of a couple problems:

  1. My OpenVDB binaries were compiled with OPENVDB_3_ABI_COMPATIBLE defined, and so were using the boost version of shared_ptr instead of the std version, but I hadn't defined OPENVDB_3_ABI_COMPATIBLE when trying to build my project, so it was trying to build using the std version; hence, undefined externals.
  2. I hadn't defined OPENEXR_DLL and HALF_EXPORTS, which is evidently required when building with those libraries, unbeknownst to me.
  3. I was compiling with the /MT option instead of the /MDd option used by half.lib

In the end, all I needed to do was define OPENEXR_DLL, HALF_EXPORTS, and OPENVDB_3_ABI_COMPATIBLE, and switch the build option to /MDd.

0
On

Try to use Vcpkg.

It supports visual studio 2015,2017

https://github.com/Microsoft/vcpkg

It's easy to use like yum in Linux.