Error "undefined reference to" (ANSI C based OPC UA SDK)

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

Moderator: uasdkc

Post Reply
mmii
Full Member
Full Member
Posts: 7
Joined: 23 Nov 2017, 15:04

Error "undefined reference to" (ANSI C based OPC UA SDK)

Post by mmii »

Hi,
I found this post: https://forum.unified-automation.com/po ... 2000#p5763.
My problem is equal to it, but the answer is not helpful because I use the ANSI C based OPC UA SDK.
Maybe, the resulting libs have other names.

I have compiled the Stack/SDK on my target platform.
The libs compiled are:
libbaselib.a
libclientlib.a
libdatalogger.a
libmodels_di.a
libmodels_plcopen.a
libserverlib.a
libserverprovider.a
libuastack.so

Libs are compiled correctly because I was able to compile the examples on the target platform. The examples run.

Now, I want to use the libraries in Eclipse for cross compiling.
Libs and include files are copied into the cross compiler directories.
The directories are marked in eclipse.

I have tried to compile server_lesson01 and server_c_demo.

Using the example of server_lesson01.
Without using the C linker flag -luastack, the function OpcUa_Trace() causes an error:
.c:73: undefined reference to `OpcUa_Trace_Imp'
Using the C linker flag -luastack, the function OpcUa_ProxyStubConfiguration_InitializeDefault causes an error:
. c:74: undefined reference to `OpcUa_ProxyStubConfiguration_InitializeDefault'.

Therefore, the libraries seems to work, but maybe, the order is not correct. Can you help me?

For the C linker flags, I set:
-lserverlib -lbaselib -luastack
and variations of this and also:
-lbaselib -lclientlib -ldatalogger -lmodels_di -lmodels_plcopen -lserverlib -lserverprovider -luastack

But nothing works. Can you help me?

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

Re: Error "undefined reference to" (ANSI C based OPC UA SDK)

Post by Support Team »

Hello mmii,

the most simple way of preventing link order problems is to add '-Wl,--start-group' before and '-Wl,--end-group' after all libraries in the link command. So you'd have something like:

/usr/bin/cc (...) examples/server_c_demo/CMakeFiles/uaserverc.dir/main_linux.c.o examples/server_c_demo/CMakeFiles/uaserverc.dir/demoserver.c.o -o examples/server_c_demo/uaservercd -Wl,--start-group src/uaserver/uaserverc/libserverlibd.a src/uaserver/uaserverc/providers/server/libserverproviderd.a src/uaserver/uaserverc/providers/models/di/libmodels_did.a src/uaserver/uaserverc/providers/models/plcopen/libmodels_plcopend.a examples/server_c_demo/demoprovider/libdemoproviderd.a src/uabase/uabasec/libbaselibd.a src/datalogger/libdataloggerd.a src/uastack/libuastackd.so -lcrypto src/uaserver/uaserverc/libserverlibd.a -lssl -lrt -lpthread -lm -Wl,--end-group (...)

Otherwise you need to take the library dependencies into account and put libraries depending on others before the other library (so libuastack would be the last, libuabase the second last and so on).
Best regards
Unified Automation Support Team

mmii
Full Member
Full Member
Posts: 7
Joined: 23 Nov 2017, 15:04

Re: Error "undefined reference to" (ANSI C based OPC UA SDK)

Post by mmii »

Thank you.
Considering your answer, I have used gcc on the target platform before using Eclipse.
I have compiled with:

Code: Select all

gcc test.c -o test -I /usr/local/include/serverlib -I /usr/local/include/baselib -I /usr/local/include/uastack -Wl,-lserverlib,-lbaselib,-luastack,-lserverprovider,-ldatalogger,-lmodels_di,-lmodels_plcopen,-lcrypto,-lmraa -fno-use-linker-plugin
This works fine.

Using

Code: Select all

-Wl,-lserverlib,-lbaselib,-luastack,-lserverprovider,-ldatalogger,-lmodels_di,-lmodels_plcopen,-lcrypto,-lmraa -fno-use-linker-plugin
in Eclipse doesn't work.
The error is still the same: undefined reference to...

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

Re: Error "undefined reference to" (ANSI C based OPC UA SDK)

Post by Support Team »

Hello mmii,

have you tried using the '-Wl,--start-group' and '-Wl,--end-group' options?

For the AnsiC based SDK we provide support for building it using CMake. With CMake, you can simply generate Eclipse projects which are configured correctly. For example:

Code: Select all

cmake -G "Eclipse CDT4 - Unix Makefiles" ..
Use cmake -h to see a list of supported CMake generators.
Best regards
Unified Automation Support Team

Post Reply