Best practice for adding aravis to cmakelist.txt

Hi guys,

Is there a best practice for adding aravis to a cmakelist.txt. (I then use this file to open my project in QT creator)? i am using aravis 0.8

So for example say I just wanted to open a connection to a camera , grab a frame and close, what is the minimum I need to add to the cmakelist.txt to get this going

Thanks in advance

Hi,

The recommended way is to use pkgconfig, something like (untested):

find_package(PkgConfig REQUIRED)                                                                                                            
                                                                                                                                            
set(DEPENDENCIES "aravis-0.8"")                                                                                                            
pkg_check_modules(DEPS REQUIRED IMPORTED_TARGET ${DEPENDENCIES})   

And later:

target_link_libraries(${PROJECT_NAME} PUBLIC PkgConfig::DEPS) 

Cheers.

Many thanks - I presume I’ll have to add the header path /usr/local/include/aravis-0.8 too to the CmakeList.txt or does this way take care of all that?

pkgconfig module should take care to set all the compilation options. But if you have installed aravis in /usr/local, you may have to set the environment variable PKG_CONFIG_PATH, most probably like:

export PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig

Super - many thanks - I’m learning all the time

Nearly there on this one I think but I’m getting undefined reference linker errors on the small test sample below. Looks like it can’t find the library files although everything looks good. I looked in the aravis-0.8.pc file and it looks like it is pointing to the right location “/usr/local/lib/x86_64-linux-gnu”. I knows it’s something stupid - just can’t see it. Any ideas what I’m doing wrong?

    ArvCamera *camera;
    ArvBuffer *buffer;

    camera = arv_camera_new (argc > 1 ? argv[1] : NULL, NULL);
    buffer = arv_camera_acquisition (camera, 0, NULL);

    if (ARV_IS_BUFFER (buffer))
        printf ("Image successfully acquired\n");
    else
        printf ("Failed to acquire a single image\n");

    g_clear_object (&camera);
    g_clear_object (&buffer);

Please attach the output of the compilation.

Appreciate the help Let me know if you need more info

CMakeFiles/object_finder.dir/apps/object_finder.cpp.o: In function `main':
object_finder.cpp:(.text.startup+0x191): undefined reference to `arv_camera_new'
object_finder.cpp:(.text.startup+0x1a0): undefined reference to `arv_camera_acquisition'
object_finder.cpp:(.text.startup+0x1a8): undefined reference to `arv_buffer_get_type'
object_finder.cpp:(.text.startup+0x1c9):CMakeFiles/object_finder.dir/build.make:442: recipe for target '/home/lasertec/Downloads/d2co/bin/object_finder' failed
CMakeFiles/Makefile2:104: recipe for target 'CMakeFiles/object_finder.dir/all' failed
Makefile:83: recipe for target 'all' failed
 undefined reference to `g_type_check_instance_is_a'
object_finder.cpp:(.text.startup+0x1e6): undefined reference to `g_object_unref'
object_finder.cpp:(.text.startup+0x1f3): undefined reference to `g_object_unref'
collect2: error: ld returned 1 exit status

Forgot to say I’m am building on Ubuntu 18.04 if that helps any

Linker parameters are missing in the log you have attached. That would help to understand where it tries to find the shared libraries.

is this any use? Not sure exaclty where it shows it in QT creator where I’m running the project from the CmakeList.txt file

/usr/lib/x86_64-linux-gnu/libfakeroot
# libc default configuration
/usr/local/lib
# CVB library dir
/opt/cvb-13.02.002/lib

/opt/cvb-13.02.002/qt
/usr/local/lib
/usr/local/lib
# Multiarch support
/usr/local/lib/x86_64-linux-gnu
/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu

Hi, just had a look at the settings in QT itself and there are some libs not found which I assume are needed. Not sure if it explains the undefined references. See screenshot below

It looks like qtcreator was able to find aravis, but not glib. Do you have the development packages installed ? Is glib installed in the same prefix as aravis ?

I guess qtreator is able to how the compilation/linking output. This output would be interresting to understand what goes wrong.

Thanks again for the help with this.

OK so I got it to compile and run when I manually found glib, gio & gobject on my system. See the screenshot where they were on my system.

What is confusing me is why they can’t be found in the /usr/lib/x86_64-linux-gnu folder automatically. Is it the .pc file for aravis telling them they should be found in the same prefix as it. Is that the normal destination for these libraries?

So I suppose I have two questions

  1. Did I do something wrong in the setup?

  2. What changes should I make in order for it to work with the CMakeList.txt as what I’ve done in QT is temporary?

Thanks in advance

Have a look at the QArv project, which is a QT based aravis viewer. It uses CMake and PkgConfig:

https://github.com/AD-Vega/qarv/blob/master/CMakeLists.txt

Excellent - I’ll take a a look