PointCloudLibrary / pcl

Point Cloud Library (PCL)
https://pointclouds.org/
Other
9.83k stars 4.6k forks source link

[compile error] Fix openNURBS compile issue under Windows #4314

Closed SunBlack closed 4 years ago

SunBlack commented 4 years ago

Currently you are getting following compile issue under windows in case you have BUILD_surface_on_nurbs enabled:

example_nurbs_viewer_surface.obj : error LNK2019: unresolved external symbol ON_ErrorEx referenced in function "public: class ONX_Model_Object & __cdecl ON_ClassArray<class ONX_Model_Object>::operator[](int)" (??A?$ON_ClassArray@VONX_Model_Object@@@@QEAAAEAVONX_Model_Object@@H@Z)
35>

Reason is the missing macro ON_DLL_TEMPLATE, caused by missing macro ON_DLL_EXPORTS

https://github.com/PointCloudLibrary/pcl/blob/8eb47684da26d42cd8cd69c79976e8aee04a2831/surface/include/pcl/surface/3rdparty/opennurbs/opennurbs_extensions.h#L139-L167

The macro will be defined here: https://github.com/PointCloudLibrary/pcl/blob/c44061819582ac6a641b20c1bbd3b44c31deb813/surface/include/pcl/surface/3rdparty/opennurbs/opennurbs_defines.h#L88-L123

To enable this block OPENNURBS_EXPORTS needs to be defined https://github.com/PointCloudLibrary/pcl/blob/c44061819582ac6a641b20c1bbd3b44c31deb813/surface/include/pcl/surface/3rdparty/opennurbs/opennurbs_defines.h#L66-L70

And surprise: OPENNURBS_EXPORTS will be never be defined.

A long time ago there was already a try to fix issues with it, but this fix was incomplete.

So we have the choice:

larshg commented 4 years ago

Which VTK version do you use?

For some reason I can't reproduce right now with the VTK9 branch I'm working on.

Though I'm not sure if it is related...

SunBlack commented 4 years ago

Do you have BUILD_surface_on_nurbs enabled? (I'm using VTK 8.2)

larshg commented 4 years ago

Yes. And the example can build and run: image

larshg commented 4 years ago

I did see this error before locally. But the only change since then is the vtk 8.2 -> vtk 9.

SunBlack commented 4 years ago

Mhm interesting. Can you try it again with VTK 8.2?

larshg commented 4 years ago

Did you build in debug? I did release.

You mention in this old PR https://github.com/PointCloudLibrary/pcl/pull/3140#issuecomment-502046839

That it happens in debug ?

SunBlack commented 4 years ago

Ah yes, Debug build

larshg commented 4 years ago

https://github.com/PointCloudLibrary/pcl/blob/c44061819582ac6a641b20c1bbd3b44c31deb813/surface/include/pcl/surface/3rdparty/opennurbs/opennurbs_error.h#L47-L53

Think we need to add either PCL_EXPORT to this.

OR add the two defines:

ON_DLL_EXPORTS ON_COMPILING_OPENNURBS

However, it now complained about linking to: ./x64/debug/zlib.lib

Needs a bit more digging :D

SunBlack commented 4 years ago

Same here with ./x64/debug/zlib.lib 😢 Until now I don't have an idea why MSVC is trying to link against it.

larshg commented 4 years ago

Its happening in this file by pragmas: https://github.com/PointCloudLibrary/pcl/blob/cc7fe363c6463a0abc617b1e17e94ab4bd4169ef/surface/include/pcl/surface/3rdparty/opennurbs/examples_linking_pragmas.h

Probably easier to add the PCL_EXPORT in front of all the debug functions.

larshg commented 4 years ago

Maybe its here rather: https://github.com/PointCloudLibrary/pcl/blob/8d5fa69f0afde84e153df6e2321ea5165b12d59c/surface/src/3rdparty/opennurbs/opennurbs_zlib.cpp