Static Linking

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

Moderator: uasdkcpp

Post Reply
praveen
Sr. Member
Sr. Member
Posts: 15
Joined: 02 Sep 2015, 14:50

Static Linking

Post by praveen »

Hello,

Is it possible to build a statically linked executable using Evaluation version ?

Thanks in Advance,
Praveen

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

Re: Static Linking

Post by Support Team »

Hello praveen,

it is NOT possible to build a statically linked executable using the Evaluation version, because the UaStack is only delivered as a shared object. If you want to build your application with only UaStack as shared object, you have to rebuild third-party libraries (OpenSSL and LibXml2) with your used compiler and link it into the application. To link also UaStack statically you have to buy the source version of the SDK.

Best Regards,

Unified Automation Support Team

praveen
Sr. Member
Sr. Member
Posts: 15
Joined: 02 Sep 2015, 14:50

Re: Static Linking

Post by praveen »

Thank you,

We would buy source edition soon,

I wanted to use uastack as a shared library, I tried changing the compiler settings to link other libraries statically except uastack. Couldn't get it done.
Is there a systematic way to get this done ?

Thanks,
Praveen

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

Re: Static Linking

Post by Support Team »

Hello praveen,

please see the documentation (http://documentation.unified-automation ... arted.html) for setting up your own application. Everything is described in this tutorial. By the way, all our examples are linked statically except to uastack, openssl and libxml2. So you can see how the compiler and linker sections are set up.

Best Regards,

Unified Automation Support Team

praveen
Sr. Member
Sr. Member
Posts: 15
Joined: 02 Sep 2015, 14:50

Re: Static Linking

Post by praveen »

Thank you ,

I have been following the tutorial since a month.

I checked the dependencies of an example binary i.e for example server hello world and I get

$ ldd server_hello_world
linux-gate.so.1 => (0xb77a7000)
libuastack.so => /home/p/sdk/bin/./../lib/libuastack.so (0xb7690000)
libpthread.so.0 => /lib/i386-linux-gnu/libpthread.so.0 (0xb765f000)
libcrypto.so.1.0.0 => /lib/i386-linux-gnu/libcrypto.so.1.0.0 (0xb74b1000)
libxml2.so.2 => /usr/lib/i386-linux-gnu/libxml2.so.2 (0xb7357000)
libstdc++.so.6 => /usr/lib/i386-linux-gnu/libstdc++.so.6 (0xb726f000)
libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0xb7229000)
libgcc_s.so.1 => /lib/i386-linux-gnu/libgcc_s.so.1 (0xb720c000)
libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb705d000)
libssl.so.1.0.0 => /lib/i386-linux-gnu/libssl.so.1.0.0 (0xb7005000)
librt.so.1 => /lib/i386-linux-gnu/librt.so.1 (0xb6ffc000)
/lib/ld-linux.so.2 (0xb77a9000)
libdl.so.2 => /lib/i386-linux-gnu/libdl.so.2 (0xb6ff7000)
libz.so.1 => /lib/i386-linux-gnu/libz.so.1 (0xb6fdd000)
liblzma.so.5 => /lib/i386-linux-gnu/liblzma.so.5 (0xb6fb6000)

If I understand correctly, all these dependencies should exist on a target machine if I were to port this application. I would like to link uastack alone dynamically.

Kindly help,

Thanks in advance
Praveen

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

Re: Static Linking

Post by Support Team »

Hello praveen,

if you want to link statically against all the system libraries, there is a section in the CMakeLists.txt file of the application server hello world, you have to edit. To do so, please open the file CMakeLists.txt of server hello world and search the linking section. Now add all the libraries you want to link against with the '.a' extension:

Code: Select all

TARGET_LINK_LIBRARIES(${PROJECT_NAME} uamodule uamodels coremodule uabase uastack ${PLATTFORM_LIBS})

should now be

TARGET_LINK_LIBRARIES(${PROJECT_NAME} rt.a uamodule uamodels coremodule uabase uastack ${PLATTFORM_LIBS})

Best Regards,

Unified Automation Support Team

praveen
Sr. Member
Sr. Member
Posts: 15
Joined: 02 Sep 2015, 14:50

Re: Static Linking

Post by praveen »

Support Team,
Thank you for your reply,

I tried various options of changing the linker flags including the one you suggested.

I am still getting some of the shared libraries like
0x00000001 (NEEDED) Shared library: [libc.so.6]
0x00000001 (NEEDED) Shared library: [libuastack.so]
0x00000001 (NEEDED) Shared library: [libpthread.so.0]
0x00000001 (NEEDED) Shared library: [libdl.so.2]

Even though I explicitly specify pthread.a dl.a etc..

Is it possible to link all other libraries statically accept libuastack.so.

Thanks in advance
Praveen

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

Re: Static Linking

Post by Support Team »

Hello praveen,

to link statically against all libraries just add the following lines before add_executable(${PROJECT_NAME} ...):

Code: Select all

SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
SET(BUILD_SHARED_LIBRARIES OFF)
SET(CMAKE_EXE_LINKER_FLAGS "-static")
This will search for all needed static libraries.


Best Regards,

Unified Automation Support Team

praveen
Sr. Member
Sr. Member
Posts: 15
Joined: 02 Sep 2015, 14:50

Re: Static Linking

Post by praveen »

Hello,

Thanks for your reply again.

I have tried these options before. And I followed your steps again.

(CMAKE_EXE_LINKER_FLAGS "-static") casues cannot find -luastack error since this library is shared (.so).

I have also tried without -static option, by indicating all the libraries with ".a" suffix except for libuastack.
The problem with this method is libuastack needs libcrypto and libpthread as shared libraries and hence the dependency
makes it difficult to build executable easy to port.


Thanks and regards,
Praveen

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

Re: Static Linking

Post by Support Team »

Hello praveen,

it seems that the best solution is to compile the whole SDK in static mode. So it makes no sense to use the Evaluation SDK for this use case. You already wrote that you will buy the source version soon, so it would be the best solution to use the source version for your use case.

Best Regards,

Unified Automation Support Team

praveen
Sr. Member
Sr. Member
Posts: 15
Joined: 02 Sep 2015, 14:50

Re: Static Linking

Post by praveen »

Support Team,

Thank you ,

I think so too.

Regards,
Praveen

Post Reply