Linker problem with SampleClient in Lession 1

Questions regarding the use of the C++ SDK for Server or Client development or integration into customer products ...

Moderator: uasdkcpp

Post Reply
HerbyS
Jr. Member
Jr. Member
Posts: 2
Joined: 11 Jan 2019, 10:40

Linker problem with SampleClient in Lession 1

Post by HerbyS »

Hello everybody.

we are developing machine control systems with Qt 5.4.1 / MinGW for Win32 (using MinGW has historical background).
To use OPC UA we got the C++ OPC SDK with source. I could compile the SDK according the Build Instructions V1.2.2 under paragraph 6.4 "Create MinGW Makefiles projects" without any problems.

Next i modified our existing OpcClient class to meet the reqirements according to your SampleClient code from Lesson 1 "Connect and Read". Commented out everything not necessary, so finally our class is the same than in the example, up to step 3.

The OPC SDK is located in the subfolder ..\OpcUaClient\, parallel to all other modules of our Control System Project and other third party modules.

Qt is compiling everything but there is some linker Problem:

Code: Select all

g++ -Wl,-s -shared -Wl,-subsystem,windows -mthreads -Wl,--out-implib,release\libXOpcLaser.a -o release\XOpcLaser.dll object_script.XOpcLaser.Release  -lglu32 -lopengl32 -lgdi32 -luser32 -L..\build-XComboBox-Desktop_Qt_5_4_1_MinGW_32bit-Release\release -L..\build-XToolButton-Desktop_Qt_5_4_1_MinGW_32bit-Release\release -L..\build-XLineEdit-Desktop_Qt_5_4_1_MinGW_32bit-Release\release -L..\_PLUGINS\XComboBox\release -L..\_PLUGINS\XToolButton\release -L..\_PLUGINS\XLineEdit\release -L..\OpcUaClient\lib -L..\OpenSSL\lib -lXLineEditDesignerPlugin -lXToolButtonDesignerPlugin -lXComboBoxDesignerPlugin -luastack.dll -luabasecpp -luapkicpp -luaclientcpp -lxmlparsercpp -lcrypto -lssl -LC:/SOFTWARE/Qt/Qt5.4.1/5.4/mingw491_32/lib -lQt5Widgets -lQt5Gui -lQt5Core

..\OpcUaClient\lib/libuabasecpp.a(statuscode.cpp.obj):statuscode.cpp:(.text$_ZN12UaStatusCode17getResponseHeaderEP20_OpcUa_RequestHeaderP21_OpcUa_ResponseHeader+0xe): undefined reference to `OpcUa_DateTime_UtcNow'
..\OpcUaClient\lib/libuabasecpp.a(statuscode.cpp.obj):statuscode.cpp:(.text$_ZNK12UaStatusCode8toStringEv+0xce): undefined reference to `OpcUa_StringA_snprintf'

Makefile.Release:116: recipe for target 'release\XOpcLaser.dll' failed

C:/SOFTWARE/Qt/Qt5.4.1/Tools/mingw491_32/bin/../lib/gcc/i686-w64-mingw32/4.9.1/../../../../i686-w64-mingw32/bin/ld.exe: ..\OpcUaClient\lib/libuabasecpp.a(statuscode.cpp.obj): bad reloc address 0xce in section `.text$_ZNK12UaStatusCode8toStringEv'

collect2.exe: error: ld returned 1 exit status
mingw32-make[1]: *** [release\XOpcLaser.dll] Error 1
mingw32-make[1]: Leaving directory 'D:/X/SOURCE/build-XOpcLaser-Desktop_Qt_5_4_1_MinGW_32bit-Release'
makefile:34: recipe for target 'release' failed
mingw32-make: *** [release] Error 2
The Qt-Projectfile looks like this:

Code: Select all

... Target definitions

# DEFINES
DEFINES += \
  WIN32_LEAN_AND_MEAN

... our own source / header / forms and resource files

OBJECTS_DIR += tempbuild

MOC_DIR += tempbuild

unix {
  Debug:DESTDIR += debug
  Release:DESTDIR += release
}

UI_DIR += tempbuild

INCLUDEPATH += \
  ... some other includes \
  ../OpcUaClient/include/uastack \
  ../OpcUaClient/include/uabasecpp \
  ../OpcUaClient/include/uaclientcpp \
  ../OpcUaClient/include/uapkicpp \
  ../OpcUaClient/include/xmlparsercpp \
  ../OpenSSL/include

Debug  : QMAKE_LIBDIR += \
  ... some other libdirs \
  ../OpcUaClient/lib \
  ../OpenSSL/lib

Release: QMAKE_LIBDIR += \
  ... some other libdirs
  ../OpcUaClient/lib \
  ../OpenSSL/lib

# LIBRARIES
LIBS += \
  -l ... some other libs \
  -luastack.dll \
  -luabasecpp \
  -luapkicpp \
  -luaclientcpp \
  -lxmlparsercpp \
  -lcrypto \
  -lssl
I feel there is still something missing, but since i'm completly new to the SDK, i have no idea what.

Best regards,
Herbert

User avatar
Support Team
Hero Member
Hero Member
Posts: 3068
Joined: 18 Mar 2011, 15:09

Re: Linker problem with SampleClient in Lession 1

Post by Support Team »

Hello HerbyS,

is looks as if you dynamically link to uastack and statically link to the SDK libs which is fine.
Do you set the define _UA_STACK_USE_DLL in your project?
Best regards
Unified Automation Support Team

HerbyS
Jr. Member
Jr. Member
Posts: 2
Joined: 11 Jan 2019, 10:40

Re: Linker problem with SampleClient in Lession 1

Post by HerbyS »

Hello,
yes, _UA_STACK_USE_DLL is set in project, together with some more already now (from the examples in lession01):

DEFINES += QT_NO_SHORTCUT WIN32_LEAN_AND_MEAN _UA_STACK_USE_DLL UNICODE _UNICODE _CRT_SECURE_NO_WARNINGS _CRT_SECURE_NO_DEPRECATE


Meantime i also built the uastack statically and tried to link, always resulting in the same two linking errors.

The only cuccessful thing was linking the project statically to a .a LIB, with dynamic and also with static uastack. But i need a DLL instead of a LIB.

Post Reply