Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
697 views
in Technique[技术] by (71.8m points)

visual studio - C++/CLI project, wraper for C++ shared library, get error

I am trying to use Open3d as C++ in managed code C#.

I managed to make a dynamic shared library of open3d as runtime library MD(Multi-threaded DLL). And then add Open3D.lib to the C++/CLI project, but when I compile it I got an LNK2005 error like below:

Error   LNK2005 "public: virtual char const * __cdecl std::exception::what(void)const " 
(?what@exception@std@@UEBAPEBDXZ) already defined in Open3D.lib(Open3D.dll) 
Open3D wrapper test C:Userspgnssource
eposOpen3dWrapperDllOpen3D wrapper testMSVCRT.lib(throw_bad_alloc.obj)    

As searching through StackOverflow, found a Link which seems the exact solution for my problem, but I can't understand the solution.

  1. Turn off CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS.
  2. Export/import explicitly the desired symbols from the DLL (using __declspec(export|import).

When I turn off CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS in CMakeLists.txt for building Open3D, I can't build the Open3d library. And It seems impossible to add __declspec(export) for every variable inside the Open3d library.

Is there any other solution for my problem? Or is there missing parts in my method to follow the Link solution?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I managed to use Open3d Library in C++/CLI by build open3d as not use static windows runtime library and not build a shared library.

It works fine when I change CMakeList options as

option(BUILD_SHARED_LIBS    "Build shared libraries"    OFF)
option (STATIC_WINDOWS_RUNTIME     "Use static (MT/MTd) Windows runtime"      OFF)

I think It is almost impossible to use the Open3D shared library in C++/CLI.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...