Compiling a simple tutorial in Ubuntu 18.04

Hi, I’ve installed the SDK and have managed to run of the bundled sample files. However, when following the tutorial in the Astra book, I get a bunch of errors…

My code is as follows:

#include <astra/astra.hpp>
#include <astra_core/astra_core.hpp>

#include <cstdio>
#include <iostream>

int main(int argc, char** argv)
{
    astra::initialize();
    astra::StreamSet streamSet;
    astra::StreamReader reader = streamSet.create_reader();
    reader.stream<astra::DepthStream>().start();
    astra::Frame frame = reader.get_latest_frame();
    const auto depthFrame = frame.get<astra::DepthFrame>();
    const int frameIndex = depthFrame.frame_index();
    const short pixelValue = depthFrame.data()[0];

    std::cout << std::endl
        << "Depth frameIndex: " << frameIndex
        << " pixelValue: " << pixelValue
        << std::endl
        << std::endl;
    astra::terminate();
    std::cout << "hit enter to exit program" << std::endl;
    std::cin.get();

    return 0;
}

My g++ compile command is:
g++ -std=c++11 -I "/home/roberto/Documents/AstraSDK/include/" -L "/home/roberto/Documents/AstraSDK/lib/" -lastra -lastra_core -lastra_core_api -o main main.cpp

The errors I get are:
/tmp/ccNhFj18.o: In function `astra::Frame::FrameRef::~FrameRef()': main.cpp:(.text._ZN5astra5Frame8FrameRefD2Ev[_ZN5astra5Frame8FrameRefD5Ev]+0x2c): undefined reference to `astra_reader_close_frame' /tmp/ccNhFj18.o: In function `astra::StreamReader::get_latest_frame(int)': main.cpp:(.text._ZN5astra12StreamReader16get_latest_frameEi[_ZN5astra12StreamReader16get_latest_frameEi]+0x91): undefined reference to `astra_reader_open_frame' /tmp/ccNhFj18.o: In function `astra::StreamReader::ReaderRef::~ReaderRef()': main.cpp:(.text._ZN5astra12StreamReader9ReaderRefD2Ev[_ZN5astra12StreamReader9ReaderRefD5Ev]+0x34): undefined reference to `astra_reader_destroy' /tmp/ccNhFj18.o: In function `astra::StreamReader::ReaderRef::ensure_callback_removed()': main.cpp:(.text._ZN5astra12StreamReader9ReaderRef23ensure_callback_removedEv[_ZN5astra12StreamReader9ReaderRef23ensure_callback_removedEv]+0x24): undefined reference to `astra_reader_unregister_frame_ready_callback' /tmp/ccNhFj18.o: In function `astra::StreamSet::StreamSetRef::connect()': main.cpp:(.text._ZN5astra9StreamSet12StreamSetRef7connectEv[_ZN5astra9StreamSet12StreamSetRef7connectEv]+0x3f): undefined reference to `astra_streamset_open' /tmp/ccNhFj18.o: In function `astra::StreamSet::StreamSetRef::~StreamSetRef()': main.cpp:(.text._ZN5astra9StreamSet12StreamSetRefD2Ev[_ZN5astra9StreamSet12StreamSetRefD5Ev]+0x28): undefined reference to `astra_streamset_close' /tmp/ccNhFj18.o: In function `astra::StreamSet::create_reader()': main.cpp:(.text._ZN5astra9StreamSet13create_readerEv[_ZN5astra9StreamSet13create_readerEv]+0x68): undefined reference to `astra_reader_create' /tmp/ccNhFj18.o: In function `astra::DataStream::DataStream(_astra_streamconnection*)': main.cpp:(.text._ZN5astra10DataStreamC2EP23_astra_streamconnection[_ZN5astra10DataStreamC5EP23_astra_streamconnection]+0x3a): undefined reference to `astra_stream_get_description' /tmp/ccNhFj18.o: In function `astra::DataStream::start()': main.cpp:(.text._ZN5astra10DataStream5startEv[_ZN5astra10DataStream5startEv]+0x5b): undefined reference to `astra_stream_start' /tmp/ccNhFj18.o: In function `astra::initialize()': main.cpp:(.text._ZN5astra10initializeEv[_ZN5astra10initializeEv]+0x5): undefined reference to `astra_initialize' /tmp/ccNhFj18.o: In function `astra::terminate()': main.cpp:(.text._ZN5astra9terminateEv[_ZN5astra9terminateEv]+0x5): undefined reference to `astra_terminate' /tmp/ccNhFj18.o: In function `astra::ImageFrame<short, 1>::ImageFrame(_astra_imageframe*, unsigned int)': main.cpp:(.text._ZN5astra10ImageFrameIsLi1EEC2EP17_astra_imageframej[_ZN5astra10ImageFrameIsLi1EEC5EP17_astra_imageframej]+0x5a): undefined reference to `astra_imageframe_get_metadata' main.cpp:(.text._ZN5astra10ImageFrameIsLi1EEC2EP17_astra_imageframej[_ZN5astra10ImageFrameIsLi1EEC5EP17_astra_imageframej]+0x8d): undefined reference to `astra_imageframe_get_frameindex' main.cpp:(.text._ZN5astra10ImageFrameIsLi1EEC2EP17_astra_imageframej[_ZN5astra10ImageFrameIsLi1EEC5EP17_astra_imageframej]+0xb3): undefined reference to `astra_imageframe_get_data_ptr' /tmp/ccNhFj18.o: In function `astra::DepthStream astra::StreamReader::stream<astra::DepthStream>(int)': main.cpp:(.text._ZN5astra12StreamReader6streamINS_11DepthStreamEEET_i[_ZN5astra12StreamReader6streamINS_11DepthStreamEEET_i]+0x96): undefined reference to `astra_reader_get_stream' /tmp/ccNhFj18.o: In function `astra::DepthFrame astra::ImageFrame<short, 1>::acquire<astra::DepthFrame>(_astra_reader_frame*, int)': main.cpp:(.text._ZN5astra10ImageFrameIsLi1EE7acquireINS_10DepthFrameEEET_P19_astra_reader_framei[_ZN5astra10ImageFrameIsLi1EE7acquireINS_10DepthFrameEEET_P19_astra_reader_framei]+0x3d): undefined reference to `astra_reader_get_imageframe' collect2: error: ld returned 1 exit status

Does anyone have any ideas? If I don’t call the astra functions, but maintain the include, it compiles correctly, so it smells like a linker problem for me.

In any case, thanks in advance for reading my first post!

Best,

Roberto

Hi Roberto,

It looks like you got the order wrong in your compile command line:

It should be okay when you do it like this:
g++ -std=c++11 -I “/home/roberto/Documents/AstraSDK/include/” -L “/home/roberto/Documents/AstraSDK/lib/” main.cpp -lastra -lastra_core -lastra_core_api -o main

Cheers,
Hans

Ah, amazing. Thank you, that compiled! Now I’m just getting a segmentation fault when running on astra_initialize, but it’s no longer a compilation issue.

Thanks again, @hanso !

Has anyone happened to encounter something like this backtrace in Ubuntu?

(gdb) b main
Breakpoint 1 at 0x2134: file main.cpp, line 8.
(gdb) r
Starting program: /home/roberto/Documents/programs/astra/main 

Breakpoint 1, main (argc=1, argv=0x7fffffffe3b8) at main.cpp:8
8	{
(gdb) l
3	
4	#include <cstdio>
5	#include <iostream>
6	
7	int main(int argc, char** argv)
8	{
9	    astra::initialize();
10	    astra::StreamSet streamSet;
11	    astra::StreamReader reader = streamSet.create_reader();
12	    reader.stream<astra::DepthStream>().start();
(gdb) s
astra::initialize () at /home/roberto/Documents/AstraSDK/include/astra_core/astra_core.hpp:32
32	        return astra_initialize();
(gdb) 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff2fdcedb in __pthread_initialize_minimal_internal () at nptl-init.c:294
294	nptl-init.c: No such file or directory.
(gdb) bt
#0  0x00007ffff2fdcedb in __pthread_initialize_minimal_internal () at nptl-init.c:294
#1  0x00007ffff2fdc681 in _init () at ../sysdeps/x86_64/crti.S:72
#2  0x0000000000000000 in ?? ()
(gdb) 

Program terminated with signal SIGSEGV, Segmentation fault.

The code is the same as above, now that it compiles.

Thanks,

-R

On this last post, I reinstalled Ubuntu 16.04 and it worked.

¯\_(ツ)_/¯

The same thing. Getting a segmentation fault when running on astra_initialize on Ubuntu 18.04. But when trying to make and run bundled examples using standard cmake/make procedure, then all is ok. Trying to build it by myself, then get segmentation fault.

1 Like

Please note that when you build using cmake your executables are built with a RUNPATH (or RPATH) tag added in the dynamic section. This RPATH is used in addition to environment variable LD_LIBRARY_PATH and the directories listed in the configuration of the dynamic loader to lookup shared objects:

$ readelf -d ../build/bin/DepthReaderEventCPP
Dynamic section at offset 0x20b28 contains 33 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [libastra_core.so]
 0x0000000000000001 (NEEDED)             Shared library: [libastra.so]
 0x0000000000000001 (NEEDED)             Shared library: [libpthread.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [libstdc++.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libgcc_s.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN/../lib:/home/hanso/devel/orbbec3d/astra/AstraSDK/lib]
...

Since the error message is rather obvious when a shared library can not be found I’m guessing you’ve set LD_LIBRARY_PATH correctly. However the application may be trying to use dlopen() to access additional shared libraries (there is a Plugins directory under lib) and this is what fails when the RPATH is not set in the executable.

I’m sorry if this is a bit vague, but I don’t have an Astra on hand to test with at the moment unfortunately.

Cheers,
Hans

Hello, hanso I tried what you wrote and compiled it, but when I tried to open ./main an error occurred:

./main: error while loading shared libraries: libastra_core.so: cannot open shared object file: No such file or directory

Searching in “/sdk/lib” i can see that libastra_core.so exist
i’ll appreciate if you can help me with that.

g++ -std=c++11 -I /home/estufab2/Documentos/AstraSDK/include -L/home/estufab2/Descargas/AstraSDK/lib main.cpp -lastra -lastra_core -lastra_core_api -o main

I think you are suffering from the same RUNPATH issue I mentioned above. Can you add -Wl,-rpath=/home/estufab2/Descargas/AstraSDK/lib to your g++ invocation and try again? This adds a linker option to add the /home/estufab2/Descargas/AstraSDK/lib directory to the runtime library search path of the executable (see “man ld” for further information).

Cheers,
Hans

Hanso i’m very grateful to you with all your help, i’m very new in Linux and Orbbec.
I tried adding rpath and it compile, but when i try to run ./main shows this: segmentation fault (core dumped)
i read about that and it seems to be a pointer issue, but the code that i am trying to compile doesn’t have it.
Thank you very much for your help and sorry but i am too new and i am trying to learn

Hi Juan,

There could be any number of reasons for the application to crash with a segmentation fault. It could also be somewhere in the library code. You could try compiling the code again with the -g option to add debug information to your executable. Then you can run the program under the debugger (gdb ./main) and use the backtrace (or bt) command when the segmentation fault occurs to see where it went wrong.

Good luck!
Hans

(gdb) bt
0 0x00007ffff2fdbedb in __pthread_initialize_minimal_internal ()
at nptl-init.c:294
1 0x00007ffff2fdb681 in _init () at …/sysdeps/x86_64/crti.S:72
2 0x0000000000000000 in ?? ()

i tried from my home, i have ubuntu 16.04 this is the result from gdb
0 0x0000000000000000 in ?? ()
1 0x00007ffff789ddc3 in std::thread::_M_start_thread(std::shared_ptrstd::thread::_Impl_base, void (*)()) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
2 0x00007fffe4ff616a in ?? ()
from /home/juan/Escritorio/AstraSDK/lib/Plugins/libOrbbecBodyTracking.so
3 0x00007fffe4efdf97 in ?? ()
from /home/juan/Escritorio/AstraSDK/lib/Plugins/libOrbbecBodyTracking.so
4 0x00007fffe4ee99d7 in ?? ()
from /home/juan/Escritorio/AstraSDK/lib/Plugins/libOrbbecBodyTracking.so
5 0x00007fffe4ee684e in ?? ()
from /home/juan/Escritorio/AstraSDK/lib/Plugins/libOrbbecBodyTracking.so
6 0x00007fffe4eca5ce in ?? ()
from /home/juan/Escritorio/AstraSDK/lib/Plugins/libOrbbecBodyTracking.so
7 0x00007fffe4eb390b in ?? ()
from /home/juan/Escritorio/AstraSDK/lib/Plugins/libOrbbecBodyTracking.so
8 0x00007fffe4eb4771 in astra_plugin_initialize ()
from /home/juan/Escritorio/AstraSDK/lib/Plugins/libOrbbecBodyTracking.so
9 0x00007ffff7bb229d in astra::plugin_manager::try_load_plugin(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&) ()
from /home/juan/Escritorio/AstraSDK/lib/libastra_core.so
10 0x00007ffff7bb310d in astra::plugin_manager::load_plugins(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&) ()
from /home/juan/Escritorio/AstraSDK/lib/libastra_core.so

Hi Juan,

You did not tell me which code you were trying to run, so I guessed it might be the code that is posted in the first article of this thread. And indeed, I got the same error!

Warning: USB events thread - failed to set priority. This might cause loss of data...
Segmentation fault (core dumped)

Using the strace utility I gathered that somebody was trying to read a configuration file from the path "../lib//data/OrbbecBodyTracking.config" which could not be found (it does not exist).

I created an empty file with the specified name in the specified path and now I get the following error message:

Warning: USB events thread - failed to set priority. This might cause loss of data...
terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::property_tree::json_parser::json_parser_error> >'
  what():  ../lib//data/OrbbecBodyTracking.config(1): expected object or array
Aborted (core dumped)

So apparently this file is supposed to contain some sort of JSON.
I downloaded the SDK User Guide but I could not find anything concerning this configuration file. I even used the strings command on the supposed culprit (libOrbbecBodyTracking.so in AstraSDK/lib/Plugins/) and extracted something that looks like JSON but which I’m pretty sure won’t work (shouldn’t work): it contains the MAC address of some server in it:

 "GestureRecognition": {
  "WavingEnabled": true
 "Skeletonization": {
  "MaxDistance": 4000,
  "AutoTracking": true,
  "Type": "RegressionSkeletonization",
  "ActiveUsers": 5,
  "FeedbackThreshold": 0.1
 "HandTracker": {
  "SkeletonSupport": true,
  "HandMode": "grab3d",
  "CoordsMode": "abs",
  "TrainedClassificator": "handtracker/svm_grab.xml"
 "Segmentation": {
  "skipFrames": 0,
  "FloorMaxError": 100,
  "Type": "user_segmentation",
  "ZPS": 575.816,
  "median": 0,
  "minHumanTTL": 0,
  "Pixelization": 0,
  "FloorDetector": "AdaptiveFloorDetector",
  "MOTION_THRESHOLD": 1,
  "MAX_DISTANCE": 7000,
  "TOFHacks": false,
  "ScaleFactor": 1.0,
  "MIN_CHECK_DISTANCE": 500
 "DepthProvider": {
  "RGB": "Off",
  "Mirror": false
 "Settings": {
  "MapResolutionX": 160,
  "MapResolutionY": 120,
  "Mode": "BT",
  "ServerMAC": "20:70:02:A0:BF:ED"
 "Filter": {
  "DummyFilter": {},
  "Kinematic": {
   "SkeletonFile": "skeleton.xml",
   "LimitsBone": "skeleton_limits.xml",
   "CfgFile": "kinematic_filter.xml",
   "Loader": "XMLSkeletonLoader"
  },
  "CombinationFilter": [
   {
    "DummyFilter": {}
   },
   {
    "Kinematic": {
     "SkeletonFile": "skeleton.xml",
     "LimitsBone": "skeleton_limits.xml",
     "CfgFile": "kinematic_filter.xml",
     "Loader": "XMLSkeletonLoader"
    }
   }
  ],
  "AlphaBeta": {
   "Alpha": 0.5,
   "Beta": 0.5
  },
  "Median": {
   "HistorySize": 5
  },
  "FABRIK": {
   "SkeletonFile": "FABRIKSkeleton.xml"
  },
  "ThreshHold": {
   "MaxDisplacement": 10000,
   "MinDisplacement": 20
 "DynamicModules": {
  "Path": "../lib/Plugins/obt/modules/",
  "Modules": [
 "OpenNIModule": {
  "FileRecord": ""
 "Orientation": {
  "GlobalUp": {},
  "TPose": {}
 "RegressionSkeletonization": {
  "Filter": {
   "CombinationFilter": [
    {
     "ThreshHold": {
      "MaxDisplacement": 200,
      "SmoothCameraJointVelocity": false,
      "MinDisplacement": 50
     }
    },
    {
     "FABRIK": {
      "PalmsAlignment": true,
      "SkeletonFile": "FABRIKSkeleton.xml"
     }
    },
    {
     "Confidence": {
      "ConfidenceThreshold": 0.5,
      "CorrectHandsConfidence": true
     }
    }
   ]
  },
  "Regression": {
   "Stat": "trees_stat",
   "Scale": 0.5,
   "MaxHeightScale": 1.4,
   "UseGPU": false,
   "MinHeightScale": 0.85,
   "Tree": "trees.bin",
   "ClassesCount": 32,
   "Bodyparts": "bodyparts.xml",
   "TreeNormCoef": 4000,
   "MeanHeight": 1700,
   "NormCoef": 4000,
   "PredictType": "base"
  },
  "Orientation": {
   "Dummy": {}
 "LicenseFile": "../license.json",
 "DefaultModules": {
  "DepthProvider": "DepthProviderManager"

You can find it just beyond N3tdv8nuitrack10middleware18PerformanceCounterE if you execute strings AstraSDK/lib/Plugins/libOrbbecBodyTracking.so | less -Sn.

I’m beginning to think this has something to do with the license you are supposed to obtain from Orbbec if you want to make use of their body tracking algorithms in your own software or something.

BTW: I built the samples from the SDK and tried a few of them, they all worked just fine!

Good luck!
Hans

Hello juenesteban182,

I was having the exact same problems you encountered in the SDK. The segmentation fault is caused by lack of -lpthread in your command. So, the complete command line should be:

g++ -std=c++11 -I /home/estufab2/Documentos/AstraSDK/include -L/home/estufab2/Descargas/AstraSDK/lib main.cpp -lastra -lastra_core -lastra_core_api -lpthread -o main

I would also like to leave some tips for people fighting against this problems(now / future):

  1. Make sure you have every dependency needed installed.(after compiling and being sucessfull with it, check with ldd , the library files to make sure you are not missing anything else… I had libpng12 missing and was also causing problems. NOTE: ubuntu 18.04 DOES NOT have libpng12, you need it to install manually).

  2. What hanso commented is right, you need to solve for the RUNPATH issue as well. To fix that, I added a file called astra.conf in /etc/ld.so.conf.d/. In that file, I added full path to astra/lib location.

  3. Do not forget to add all the flags necessary for compilation: -lastra -lastra_core -lastra_core_api -lpthread as well add your -I and -L paths.

Hopefully, this can save some headaches for some people(as I had to suffer them myself haha).

Best regards,
Alexandre

Hi,
there is one more thing to do, I lost one day on this…
FFmpeg is required!! So install it in Ubuntu 16.04…

Without FFMpeg I was not able to run the compiled samples, and also the simple program reported here. Everything crashed with segmentation fault.

Why can’t I initialize astra? I can successfully run SimpleStreamViewer-SFML
int main(int argc, char** argv)
{
astra::initialize();
std::cout << “initialized\n”;

astra::terminate();
std::cout << "hit enter to exit program" << std::endl;
std::cin.get();

return 0;

}

Compile with

g++ -std=c++11 -Wl,-rpath=/path/to/lib -I /path/to/include -L /path/to/lib -g main.cpp -lastra -lastra_core -lastra_core_api -o main

Output
Warning: USB events thread - failed to set priority. This might cause loss of data…
unsupported descriptor subtype VS_COLORFORMAT
attempt to claim already-claimed interface 1
Segmentation fault (core dumped)