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

Open62541pp Linker error when compiling on windows with dynamic linkage #287

Closed
pemartin2 opened this issue May 24, 2024 · 3 comments · Fixed by #290
Closed

Open62541pp Linker error when compiling on windows with dynamic linkage #287

pemartin2 opened this issue May 24, 2024 · 3 comments · Fixed by #290

Comments

@pemartin2
Copy link

pemartin2 commented May 24, 2024

Hi @lukasberbuer, another windows specific issue :-)

Introduced with 5357ee9, reproducible with v0.13.0

Building unresolved external symbol UA_VariableAttributes_default (and similar)

Steps to reproduce

  • Windows OS
  • Checkout version 5357ee9 of this repo (probably master or v0.13.0 will also do but not tested)
  • Compile with dev configuration with modified BUILD_SHARED_LIBS": "ON"
  • To have a simplified case: In tests\CMakeList.txt add_executable comment out all tests except Server.cpp (and main.cpp)
  • --> Compilation results in unresolved external symbol UA_VariableAttributes_default

Workarounds:

  • Change the include order either by setting cmake variable UA_ENABLE_AMALGAMATION
  • Or in tests\Server.cpp just add a #include <open62541/server_config_default.h> above the open62541pp includes. Probably open62541/server.h is enough, forgot to test this.

Solution (not sure if it's the best and cleanest one):

In include\open62541pp\types instead of

#ifndef UA_DEFAULT_ATTRIBUTES_DEFINED
#define UA_DEFAULT_ATTRIBUTES_DEFINED
extern "C" const UA_VariableAttributes UA_VariableAttributes_default;
extern "C" const UA_VariableTypeAttributes UA_VariableTypeAttributes_default;
extern "C" const UA_MethodAttributes UA_MethodAttributes_default;
extern "C" const UA_ObjectAttributes UA_ObjectAttributes_default;
extern "C" const UA_ObjectTypeAttributes UA_ObjectTypeAttributes_default;
extern "C" const UA_ReferenceTypeAttributes UA_ReferenceTypeAttributes_default;
extern "C" const UA_DataTypeAttributes UA_DataTypeAttributes_default;
extern "C" const UA_ViewAttributes UA_ViewAttributes_default;
#endif

simply add the open62541 header #include "open62541/server.h" instead. This results in dllexport in open62541 and dllimport in open62541pp and the user's code.
I did not think too much about it but did not find a way to only declare the xxx_default parameters because this will collide with open62541\server.h.

@lukasberbuer
Copy link
Member

lukasberbuer commented May 25, 2024

Thanks again for catching bugs 😊

I updated the CI pipeline to both build static and shared libraries with Windows, Linux, macOS and different compilers: #288
And indeed the error revealed itself: https://github.com/open62541pp/open62541pp/actions/runs/9233973823/job/25407044441

Fix coming soon

@lukasberbuer
Copy link
Member

@pemartin2, can you please verify the fix?

@pemartin2
Copy link
Author

@lukasberbuer. Confirmed that the fix worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants