Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
SunBlack opened this issue Aug 10, 2020 · 11 comments · Fixed by #4315
Closed

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

SunBlack opened this issue Aug 10, 2020 · 11 comments · Fixed by #4315
Labels
kind: compile error Type of issue status: triage Labels incomplete

Comments

@SunBlack
Copy link
Contributor

SunBlack commented Aug 10, 2020

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

#if defined(ON_DLL_TEMPLATE)
// This stuff is here because of a limitation in the way Microsoft
// handles templates and DLLs. See Microsoft's knowledge base
// article ID Q168958 for details.
#pragma warning( push )
#pragma warning( disable : 4231 )
ON_DLL_TEMPLATE template class ON_CLASS ON_SimpleArray<ON_Bitmap*>;
ON_DLL_TEMPLATE template class ON_CLASS ON_ClassArray<ON_Linetype>;
ON_DLL_TEMPLATE template class ON_CLASS ON_ObjectArray<ON_Linetype>;
ON_DLL_TEMPLATE template class ON_CLASS ON_ClassArray<ON_Layer>;
ON_DLL_TEMPLATE template class ON_CLASS ON_ObjectArray<ON_Layer>;
ON_DLL_TEMPLATE template class ON_CLASS ON_ClassArray<ON_Group>;
ON_DLL_TEMPLATE template class ON_CLASS ON_ObjectArray<ON_Group>;
ON_DLL_TEMPLATE template class ON_CLASS ON_ClassArray<ON_Font>;
ON_DLL_TEMPLATE template class ON_CLASS ON_ObjectArray<ON_Font>;
ON_DLL_TEMPLATE template class ON_CLASS ON_ClassArray<ON_DimStyle>;
ON_DLL_TEMPLATE template class ON_CLASS ON_ObjectArray<ON_DimStyle>;
ON_DLL_TEMPLATE template class ON_CLASS ON_ClassArray<ONX_Model_RenderLight>;
ON_DLL_TEMPLATE template class ON_CLASS ON_ClassArray<ON_HatchPattern>;
ON_DLL_TEMPLATE template class ON_CLASS ON_ObjectArray<ON_HatchPattern>;
ON_DLL_TEMPLATE template class ON_CLASS ON_ClassArray<ON_InstanceDefinition>;
ON_DLL_TEMPLATE template class ON_CLASS ON_ObjectArray<ON_InstanceDefinition>;
ON_DLL_TEMPLATE template class ON_CLASS ON_ClassArray<ONX_Model_Object>;
ON_DLL_TEMPLATE template class ON_CLASS ON_ClassArray<ONX_Model_UserData>;
ON_DLL_TEMPLATE template class ON_CLASS ON_SimpleArray<ON_HistoryRecord*>;
#pragma warning( pop )
#endif

The macro will be defined here:

#if defined(ON_DLL_EXPORTS)
#if !defined(ON_COMPILING_OPENNURBS)
#error When compiling an OpenNURBS DLL, ON_DLL_EXPORTS must be defined
#endif
/* compiling OpenNurbs as a Windows DLL - export classes, functions, templates, and globals */
#define ON_CLASS __declspec(dllexport)
#define ON_DECL __declspec(dllexport)
#define ON_EXTERN_DECL __declspec(dllexport)
#define ON_DLL_TEMPLATE
#elif defined(ON_DLL_IMPORTS)
#if defined(ON_COMPILING_OPENNURBS)
#error When compiling an OpenNURBS DLL, ON_DLL_IMPORTS must NOT be defined
#endif
/* using OpenNurbs as a Windows DLL - import classes, functions, templates, and globals */
#define ON_CLASS __declspec(dllimport)
#define ON_DECL __declspec(dllimport)
#define ON_EXTERN_DECL __declspec(dllimport)
#define ON_DLL_TEMPLATE extern
#else
/* compiling or using OpenNurbs as a static library */
#define ON_CLASS
#define ON_DECL
#define ON_EXTERN_DECL
#if defined(ON_DLL_TEMPLATE)
#undef ON_DLL_TEMPLATE
#endif
#endif

To enable this block OPENNURBS_EXPORTS needs to be defined

#if defined(OPENNURBS_EXPORTS)
// OPENNURBS_EXPORTS is Microsoft's prefered defined for building an opennurbs DLL.
#if !defined(ON_DLL_EXPORTS)
#define ON_DLL_EXPORTS
#endif

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:

  • Adding OPENNURBS_EXPORTS flag: In this case we need to export OPENNURBS_IMPORTS, too and revert the old fix. Otherwise you are getting tons of warnings: warning C4141: 'dllexport': used more than once (compiling source file C:\dev\pcl\surface\src\3rdparty\opennurbs\opennurbs_3dm_attributes.cpp)
  • Replacing ON_CLASS and all other openNURBS specific macros by e.g. PCL_EXPORTS. In this case we have currently no replacement for e.g. ON_DLL_TEMPLATE
@SunBlack SunBlack added kind: compile error Type of issue status: triage Labels incomplete labels Aug 10, 2020
@larshg
Copy link
Contributor

larshg commented Aug 10, 2020

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
Copy link
Contributor Author

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

@larshg
Copy link
Contributor

larshg commented Aug 10, 2020

Yes. And the example can build and run:
image

@larshg
Copy link
Contributor

larshg commented Aug 10, 2020

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

@SunBlack
Copy link
Contributor Author

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

@larshg
Copy link
Contributor

larshg commented Aug 10, 2020

Did you build in debug? I did release.

You mention in this old PR #3140 (comment)

That it happens in debug ?

@SunBlack
Copy link
Contributor Author

Ah yes, Debug build

@larshg
Copy link
Contributor

larshg commented Aug 10, 2020

ON_DECL
void ON_ErrorMessage(
int, /* 0 = warning message, 1 = serious error message, 2 = assert failure */
const char*
);
/*

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
Copy link
Contributor Author

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

@larshg
Copy link
Contributor

larshg commented Aug 10, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: compile error Type of issue status: triage Labels incomplete
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants