Compiling Cumulocity C++ Library

Hi guys it’ Luca,
I’m trying to compile the sdk c++ library with no success.

My OS: “Debian GNU/Linux 11 (bullseye)”

The only misssing prerequisites was libcurl so I did:

apt install libcurl4-openssl-dev

I don’t need lua so I edited init.mk like so:

SR_PLUGIN_LUA:=0
CPPFLAGS:=$(shell pkg-config --cflags libcurl lua)
CXXFLAGS:=-Wall -pedantic -Wextra
LDLIBS:=$(shell pkg-config --libs libcurl lua)

Then follwoing the rest of the tutorial but I don’t know what to do about this:

  • Starts developing your Cumulocity agent and link it to the library with -lsera.

What should I do? Should I do something on MakeFile?

Then, ignoring the previous point I tried to run:

make release

Results in error:

Package lua was not found in the pkg-config search path.
Perhaps you should add the directory containing `lua.pc'
to the PKG_CONFIG_PATH environment variable
No package 'lua' found
Package lua was not found in the pkg-config search path.
Perhaps you should add the directory containing `lua.pc'
to the PKG_CONFIG_PATH environment variable
No package 'lua' found
Package lua was not found in the pkg-config search path.
Perhaps you should add the directory containing `lua.pc'
to the PKG_CONFIG_PATH environment variable
No package 'lua' found
Package lua was not found in the pkg-config search path.
Perhaps you should add the directory containing `lua.pc'
to the PKG_CONFIG_PATH environment variable
No package 'lua' found
(CXX) build/smartrest.o
(CXX) build/sragent.o
(CXX) build/srbootstrap.o
(CXX) build/srdevicepush.o
src/srdevicepush.cc: In static member function ‘static void* SrDevicePush::func(void*)’:
src/srdevicepush.cc:102:17: warning: this statement may fall through [-Wimplicit-fallthrough=]
  102 |                 }
      |                 ^
src/srdevicepush.cc:106:13: note: here
  106 |             case BAYEUX_STATE_SUBSCRIBE:
      |             ^~~~
src/srdevicepush.cc:130:17: warning: this statement may fall through [-Wimplicit-fallthrough=]
  130 |                 }
      |                 ^
src/srdevicepush.cc:134:13: note: here
  134 |             case BAYEUX_STATE_CONNECT:
      |             ^~~~
(CXX) build/srlogger.o
(CXX) build/srnetbinhttp.o
(CXX) build/srnethttp.o
(CXX) build/srnetinterface.o
(CXX) build/srnetmqtt.o
(CXX) build/srnetsocket.o
(CXX) build/srreporter.o
(CXX) build/srtimer.o
(CXX) build/srutils.o
(CC) build/MQTTConnectClient.o
(CC) build/MQTTConnectServer.o
(CC) build/MQTTDeserializePublish.o
(CC) build/MQTTFormat.o
(CC) build/MQTTPacket.o
(CC) build/MQTTSerializePublish.o
(CC) build/MQTTSubscribeClient.o
(CC) build/MQTTSubscribeServer.o
(CC) build/MQTTUnsubscribeClient.o
(CC) build/MQTTUnsubscribeServer.o
(LD) lib/libsera.so.1.2.7
/usr/bin/ld: /tmp/libsera.so.1.2.7.JQ8g6r.ltrans0.ltrans.o: in function `SrAgent::~SrAgent()':
<artificial>:(.text+0x870): undefined reference to `curl_global_cleanup'
/usr/bin/ld: /tmp/libsera.so.1.2.7.JQ8g6r.ltrans0.ltrans.o: in function `SrNetInterface::~SrNetInterface()':
<artificial>:(.text+0xc08): undefined reference to `curl_easy_cleanup'
/usr/bin/ld: /tmp/libsera.so.1.2.7.JQ8g6r.ltrans0.ltrans.o: in function `SrNetBinHttp::~SrNetBinHttp()':
<artificial>:(.text+0xc84): undefined reference to `curl_slist_free_all'
/usr/bin/ld: /tmp/libsera.so.1.2.7.JQ8g6r.ltrans0.ltrans.o: in function `SrNetHttp::~SrNetHttp()':
<artificial>:(.text+0xcf8): undefined reference to `curl_slist_free_all'
/usr/bin/ld: /tmp/libsera.so.1.2.7.JQ8g6r.ltrans0.ltrans.o: in function `SrAgent::SrAgent(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, SrIntegrate*, SrBootstrap*)':
<artificial>:(.text+0x1b30): undefined reference to `curl_global_init'
/usr/bin/ld: /tmp/libsera.so.1.2.7.JQ8g6r.ltrans0.ltrans.o: in function `SrNetBinHttp::post(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
<artificial>:(.text+0x45a0): undefined reference to `curl_formadd'
/usr/bin/ld: <artificial>:(.text+0x45c4): undefined reference to `curl_formadd'
/usr/bin/ld: <artificial>:(.text+0x4614): undefined reference to `curl_formadd'
/usr/bin/ld: <artificial>:(.text+0x4628): undefined reference to `curl_easy_setopt'
/usr/bin/ld: <artificial>:(.text+0x463c): undefined reference to `curl_easy_setopt'
/usr/bin/ld: <artificial>:(.text+0x464c): undefined reference to `curl_easy_setopt'
/usr/bin/ld: <artificial>:(.text+0x465c): undefined reference to `curl_easy_setopt'
/usr/bin/ld: <artificial>:(.text+0x4664): undefined reference to `curl_easy_perform'
/usr/bin/ld: <artificial>:(.text+0x4670): undefined reference to `curl_formfree'
/usr/bin/ld: /tmp/libsera.so.1.2.7.JQ8g6r.ltrans0.ltrans.o: in function `SrNetBinHttp::postf(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
<artificial>:(.text+0x4e60): undefined reference to `curl_formadd'
/usr/bin/ld: <artificial>:(.text+0x4e84): undefined reference to `curl_formadd'
/usr/bin/ld: <artificial>:(.text+0x4ec4): undefined reference to `curl_formadd'
/usr/bin/ld: <artificial>:(.text+0x4ed8): undefined reference to `curl_easy_setopt'
/usr/bin/ld: <artificial>:(.text+0x4eec): undefined reference to `curl_easy_setopt'
/usr/bin/ld: <artificial>:(.text+0x4efc): undefined reference to `curl_easy_setopt'
/usr/bin/ld: <artificial>:(.text+0x4f0c): undefined reference to `curl_easy_setopt'
/usr/bin/ld: <artificial>:(.text+0x4f14): undefined reference to `curl_easy_perform'
/usr/bin/ld: <artificial>:(.text+0x4f20): undefined reference to `curl_formfree'
/usr/bin/ld: /tmp/libsera.so.1.2.7.JQ8g6r.ltrans0.ltrans.o: in function `SrNetBinHttp::get(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
<artificial>:(.text+0x52a4): undefined reference to `curl_easy_setopt'
/usr/bin/ld: <artificial>:(.text+0x52b4): undefined reference to `curl_easy_setopt'
/usr/bin/ld: <artificial>:(.text+0x52e8): undefined reference to `curl_easy_setopt'
/usr/bin/ld: <artificial>:(.text+0x5308): undefined reference to `curl_easy_setopt'
/usr/bin/ld: <artificial>:(.text+0x5310): undefined reference to `curl_easy_perform'
/usr/bin/ld: /tmp/libsera.so.1.2.7.JQ8g6r.ltrans0.ltrans.o: in function `SrNetBinHttp::getf(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
<artificial>:(.text+0x57a0): undefined reference to `curl_easy_setopt'
/usr/bin/ld: <artificial>:(.text+0x57b0): undefined reference to `curl_easy_setopt'
/usr/bin/ld: <artificial>:(.text+0x57c0): undefined reference to `curl_easy_setopt'
/usr/bin/ld: <artificial>:(.text+0x57fc): undefined reference to `curl_easy_setopt'
/usr/bin/ld: <artificial>:(.text+0x5814): undefined reference to `curl_easy_perform'
/usr/bin/ld: /tmp/libsera.so.1.2.7.JQ8g6r.ltrans0.ltrans.o: in function `SrNetHttp::post(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
<artificial>:(.text+0x5ad0): undefined reference to `curl_easy_setopt'
/usr/bin/ld: <artificial>:(.text+0x5ae0): undefined reference to `curl_easy_setopt'
/usr/bin/ld: <artificial>:(.text+0x5ae8): undefined reference to `curl_easy_perform'
/usr/bin/ld: <artificial>:(.text+0x5b34): undefined reference to `curl_easy_getinfo'
/usr/bin/ld: /tmp/libsera.so.1.2.7.JQ8g6r.ltrans0.ltrans.o: in function `SrNetInterface::SrNetInterface(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
<artificial>:(.text+0x5c6c): undefined reference to `curl_easy_init'
/usr/bin/ld: <artificial>:(.text+0x5c7c): undefined reference to `curl_easy_setopt'
/usr/bin/ld: <artificial>:(.text+0x5c8c): undefined reference to `curl_easy_setopt'
/usr/bin/ld: /tmp/libsera.so.1.2.7.JQ8g6r.ltrans0.ltrans.o: in function `SrNetBinHttp::SrNetBinHttp(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
<artificial>:(.text+0x5d4c): undefined reference to `curl_slist_append'
/usr/bin/ld: <artificial>:(.text+0x5d58): undefined reference to `curl_slist_append'
/usr/bin/ld: <artificial>:(.text+0x5d6c): undefined reference to `curl_easy_setopt'
/usr/bin/ld: <artificial>:(.text+0x5d7c): undefined reference to `curl_easy_setopt'
/usr/bin/ld: /tmp/libsera.so.1.2.7.JQ8g6r.ltrans0.ltrans.o: in function `SrNetHttp::SrNetHttp(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
<artificial>:(.text+0x5e18): undefined reference to `curl_slist_append'
/usr/bin/ld: <artificial>:(.text+0x5e24): undefined reference to `curl_slist_append'
/usr/bin/ld: <artificial>:(.text+0x5e2c): undefined reference to `curl_slist_append'
/usr/bin/ld: <artificial>:(.text+0x5e50): undefined reference to `curl_easy_setopt'
/usr/bin/ld: <artificial>:(.text+0x5e64): undefined reference to `curl_easy_setopt'
/usr/bin/ld: <artificial>:(.text+0x5e74): undefined reference to `curl_easy_setopt'
/usr/bin/ld: <artificial>:(.text+0x5e84): undefined reference to `curl_easy_setopt'
/usr/bin/ld: <artificial>:(.text+0x5e98): undefined reference to `curl_easy_setopt'
/usr/bin/ld: /tmp/libsera.so.1.2.7.JQ8g6r.ltrans0.ltrans.o:<artificial>:(.text+0x5ea8): more undefined references to `curl_easy_setopt' follow
/usr/bin/ld: /tmp/libsera.so.1.2.7.JQ8g6r.ltrans0.ltrans.o: in function `SrNetHttp::SrNetHttp(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
<artificial>:(.text+0x5ee8): undefined reference to `curl_slist_append'
/usr/bin/ld: /tmp/libsera.so.1.2.7.JQ8g6r.ltrans0.ltrans.o: in function `SrNetInterface::setTimeout(long)':
<artificial>:(.text+0x6694): undefined reference to `curl_easy_setopt'
/usr/bin/ld: /tmp/libsera.so.1.2.7.JQ8g6r.ltrans0.ltrans.o: in function `SrNetInterface::setDebug(long)':
<artificial>:(.text+0x7c4c): undefined reference to `curl_easy_setopt'
/usr/bin/ld: /tmp/libsera.so.1.2.7.JQ8g6r.ltrans0.ltrans.o: in function `SrNetSocket::SrNetSocket(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
<artificial>:(.text+0x7e84): undefined reference to `curl_easy_setopt'
/usr/bin/ld: <artificial>:(.text+0x7e94): undefined reference to `curl_easy_setopt'
/usr/bin/ld: /tmp/libsera.so.1.2.7.JQ8g6r.ltrans0.ltrans.o: in function `SrNetSocket::connect()':
<artificial>:(.text+0x7ff8): undefined reference to `curl_easy_setopt'
/usr/bin/ld: <artificial>:(.text+0x802c): undefined reference to `curl_easy_perform'
/usr/bin/ld: /tmp/libsera.so.1.2.7.JQ8g6r.ltrans0.ltrans.o: in function `SrNetSocket::sendBuf(char const*, unsigned long)':
<artificial>:(.text+0x81e0): undefined reference to `curl_easy_getinfo'
/usr/bin/ld: <artificial>:(.text+0x821c): undefined reference to `curl_easy_send'
/usr/bin/ld: /tmp/libsera.so.1.2.7.JQ8g6r.ltrans0.ltrans.o: in function `SrNetSocket::recv(unsigned long)':
<artificial>:(.text+0x83e0): undefined reference to `curl_easy_getinfo'
/usr/bin/ld: <artificial>:(.text+0x8418): undefined reference to `curl_easy_recv'
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:78: lib/libsera.so.1.2.7] Error 1
make: *** [Makefile:67: release] Error 2

Best
Luca

Hello Luca,

might it be, that lua is internally used by another lb you are referring to?

Does the build succeed if you do not disclose lua from the build path.

Regards,
Holger

Hello Holger,
let me give it a try

best
Luca

I enabled lua editing init.mk

SR_PLUGIN_LUA:=1
CPPFLAGS:=$(shell pkg-config --cflags libcurl lua)
CXXFLAGS:=-Wall -pedantic -Wextra
LDLIBS:=$(shell pkg-config --libs libcurl lua)

Installed lua:

apt install lua5.3
~/c8y/cumulocity-sdk-c# lua -v
Lua 5.3.3  Copyright (C) 1994-2016 Lua.org, PUC-Rio

But I think Im missing something macroscopic:

Package lua was not found in the pkg-config search path.
Perhaps you should add the directory containing `lua.pc'
to the PKG_CONFIG_PATH environment variable
No package 'lua' found
Package lua was not found in the pkg-config search path.
Perhaps you should add the directory containing `lua.pc'
to the PKG_CONFIG_PATH environment variable
No package 'lua' found
Package lua was not found in the pkg-config search path.
Perhaps you should add the directory containing `lua.pc'
to the PKG_CONFIG_PATH environment variable
No package 'lua' found
Package lua was not found in the pkg-config search path.
Perhaps you should add the directory containing `lua.pc'
to the PKG_CONFIG_PATH environment variable
No package 'lua' found
(CXX) build/srluapluginmanager.o
In file included from src/srluapluginmanager.cc:21:
include/srluapluginmanager.h:29:10: fatal error: lua.h: No such file or directory
   29 | #include <lua.h>
      |          ^~~~~~~
compilation terminated.
make[1]: *** [Makefile:85: build/srluapluginmanager.o] Error 1
make: *** [Makefile:67: release] Error 2

Hi Luca,

could you go back to the initial setup with Lua disabled and remove “lua” from both the CPPFLAGS and the LDLIBS. Though to me it looks like libcurl is not properly installed and not found during the build process. Can you check if it is part of the library path?

Starts developing your Cumulocity agent and link it to the library with -lsera.

This just means you can use the built library for your own development if the previous make step was complete.

Note, that there has been no active development on this library for a couple of years. Do you need to do things in C++ or could you also use e.g. .NET?

Hi Harald,
thank you for your help.

I tried what you suggest and the result seems fine:

 make release
(CXX) build/srnetbinhttp.o
(CXX) build/srnethttp.o
(CXX) build/srnetinterface.o
(CXX) build/srnetmqtt.o
(CXX) build/srnetsocket.o
(CXX) build/srreporter.o
(CXX) build/srtimer.o
(CXX) build/srutils.o
(CC) build/MQTTConnectClient.o
(CC) build/MQTTConnectServer.o
(CC) build/MQTTDeserializePublish.o
(CC) build/MQTTFormat.o
(CC) build/MQTTPacket.o
(CC) build/MQTTSerializePublish.o
(CC) build/MQTTSubscribeClient.o
(CC) build/MQTTSubscribeServer.o
(CC) build/MQTTUnsubscribeClient.o
(CC) build/MQTTUnsubscribeServer.o
(LD) lib/libsera.so.1.2.7
(LD) bin/srwatchdogd

in folder lib I have:

drwxr-xr-x  2 root root   4096 Dec  4 15:09 .
drwxr-xr-x 14 root root   4096 Dec  4 15:09 ..
lrwxrwxrwx  1 root root     12 Dec  4 15:09 libsera.so -> libsera.so.1
lrwxrwxrwx  1 root root     16 Dec  4 15:09 libsera.so.1 -> libsera.so.1.2.7
-rwxr-xr-x  1 root root 294728 Dec  4 15:09 libsera.so.1.2.7

Note, that there has been no active development on this library for a couple of years. Do you need to do things in C++ or could you also use e.g. .NET?

Actually our goal is to talk to my remote devices through Cloud Remote Access. So I need Cumulocity Linux Agent which depends on the library im compiling.

After your question im wondering if the linux agent mentioned here in the cloud remote access docs is the same that I’m trying to get working.

Hi Luca,

the Linux agent is not the only agent supporting Cloud Remote Access. For example thin-edge also supports this feature. This article gives you an overview of different options:

And this session recording from earlier this year shows how to use it with thin-edge:

Best regards,
Harald