Search code examples
c++graphics3dqt-creatorraytracing

How to link an external library in Qt Creator when LIBS += -L"..." doesn't seem to work?


I've been trying to use the Intel Open Image Denoise library in my code but still have no luck as of now. Apparently it seems that I am not linking the library properly.

Here's what I've done so far: after compiling OIDN I moved the oidn directory to the directory where my path tracer code is and did the following in my code (C++11) which I'm working on in Qt Creator.

#include "oidn/include/OpenImageDenoise/oidn.hpp"
.
.
.
oidn::DeviceRef device = oidn::newDevice(); // this is where things break
device.commit();

Note that doing #include "oidn/include/OpenImageDenoise/oidn.hpp" seems to work fine because autocomplete works for oidn and shows its members. However I get the following errors which seems to be due to not linking oidn libraries.

enter image description here

I tried linking the libraries via LIBS += -L"oidn/build/" or LIBS += -L"oidn/build/libOpenImageDenoise.so" (as shown in the image) but I get the same errors. I also appended -loidn but got an error saying "cannot find -loidn". I am now pretty confused on what I'm supposed to do. I'm not even sure if the errors are due to not properly linking libraries because I see people generally link libraries in C++ the same way I am trying to do it here. I would really appreciate if someone can help me figure out what I need to do to get OIDN work.


Solution

  • All the previous answers/comments were correct. The weird thing about my case was the symlinks of the libraries in the build directory were not valid and were not pointing to the right files. The output of ls -lh /home/Warrior/Desktop/pathtracer/oidn/build was as follow:

    total 160K
    drwxrwxr-x 4 amir amir 4.0K Feb  4 00:09 apps
    -rw-rw-r-- 1 amir amir  19K Feb  4 00:09 CMakeCache.txt
    drwxrwxr-x 7 amir amir 4.0K Feb  4 00:09 CMakeFiles
    -rw-rw-r-- 1 amir amir 6.5K Feb  4 00:09 cmake_install.cmake
    drwxrwxr-x 3 amir amir 4.0K Feb  4 00:09 common
    -rw-r--r-- 1 amir amir 3.6K Feb  4 00:09 CPackConfig.cmake
    -rw-r--r-- 1 amir amir 4.0K Feb  4 00:09 CPackSourceConfig.cmake
    -rw-rw-r-- 1 amir amir 103K Feb  4 00:09 Makefile
    drwxrwxr-x 3 amir amir 4.0K Feb  4 00:08 mkl-dnn
    -rw-r--r-- 1 amir amir 1.6K Feb  4 00:09 OpenImageDenoiseConfigVersion.cmake
    

    But when I would go to the directory I would see the following:

    enter image description here

    What I did was instead of cloning the oidn repo somewhere else and building it, I cloned the oidn repo in /home/Warrior/Desktop/pathtracer/ and built it there. After that I could see the correct file names/symlinks via ls -lh as follow. Now my program compiles and things work fine. I just had to use LIBS += -L"oidn/build/" -lOpenImageDenoise when compiling my code:

    total 51M
    drwxrwxr-x 4 amir amir 4.0K Feb  9 10:14 apps
    -rw-rw-r-- 1 amir amir  19K Feb  9 10:14 CMakeCache.txt
    drwxrwxr-x 7 amir amir 4.0K Feb  9 10:19 CMakeFiles
    -rw-rw-r-- 1 amir amir 5.6K Feb  9 10:14 cmake_install.cmake
    -rw-rw-r-- 1 amir amir 2.5K Feb  9 10:17 color_ispc_avx2.h
    -rw-rw-r-- 1 amir amir 2.5K Feb  9 10:17 color_ispc_avx512skx.h
    -rw-rw-r-- 1 amir amir 3.1K Feb  9 10:17 color_ispc.h
    -rw-rw-r-- 1 amir amir 2.5K Feb  9 10:17 color_ispc_sse4.h
    drwxrwxr-x 3 amir amir 4.0K Feb  9 10:14 common
    -rw-r--r-- 1 amir amir 3.3K Feb  9 10:14 CPackConfig.cmake
    -rw-r--r-- 1 amir amir 3.7K Feb  9 10:14 CPackSourceConfig.cmake
    -rw-rw-r-- 1 amir amir 2.6K Feb  9 10:17 input_reorder_ispc_avx2.h
    -rw-rw-r-- 1 amir amir 2.6K Feb  9 10:17 input_reorder_ispc_avx512skx.h
    -rw-rw-r-- 1 amir amir 3.1K Feb  9 10:17 input_reorder_ispc.h
    -rw-rw-r-- 1 amir amir 2.6K Feb  9 10:17 input_reorder_ispc_sse4.h
    -rw-rw-r-- 1 amir amir  41K Feb  9 10:14 libcommon.a
    -rw-rw-r-- 1 amir amir  16M Feb  9 10:17 libdnnl.a
    lrwxrwxrwx 1 amir amir   24 Feb  9 10:19 libOpenImageDenoise.so -> libOpenImageDenoise.so.0
    lrwxrwxrwx 1 amir amir   28 Feb  9 10:19 libOpenImageDenoise.so.0 -> libOpenImageDenoise.so.1.3.0
    -rwxrwxr-x 1 amir amir  34M Feb  9 10:19 libOpenImageDenoise.so.1.3.0
    -rw-rw-r-- 1 amir amir  37K Feb  9 10:19 libutils.a
    drwxrwxr-x 2 amir amir 4.0K Feb  9 10:17 local__core
    -rw-rw-r-- 1 amir amir 104K Feb  9 10:14 Makefile
    drwxrwxr-x 3 amir amir 4.0K Feb  9 10:14 mkl-dnn
    -rwxrwxr-x 1 amir amir 181K Feb  9 10:19 oidnBenchmark
    -rwxrwxr-x 1 amir amir  59K Feb  9 10:19 oidnDenoise
    -rwxrwxr-x 1 amir amir 882K Feb  9 10:19 oidnTest
    -rw-r--r-- 1 amir amir 1.6K Feb  9 10:14 OpenImageDenoiseConfigVersion.cmake
    -rw-rw-r-- 1 amir amir 1.5K Feb  9 10:17 output_copy_ispc_avx2.h
    -rw-rw-r-- 1 amir amir 1.5K Feb  9 10:17 output_copy_ispc_avx512skx.h
    -rw-rw-r-- 1 amir amir 1.9K Feb  9 10:17 output_copy_ispc.h
    -rw-rw-r-- 1 amir amir 1.5K Feb  9 10:17 output_copy_ispc_sse4.h
    -rw-rw-r-- 1 amir amir 2.5K Feb  9 10:17 output_reorder_ispc_avx2.h
    -rw-rw-r-- 1 amir amir 2.5K Feb  9 10:17 output_reorder_ispc_avx512skx.h
    -rw-rw-r-- 1 amir amir 3.1K Feb  9 10:17 output_reorder_ispc.h
    -rw-rw-r-- 1 amir amir 2.5K Feb  9 10:17 output_reorder_ispc_sse4.h
    -rw-rw-r-- 1 amir amir 1.5K Feb  9 10:17 upsample_ispc_avx2.h
    -rw-rw-r-- 1 amir amir 1.5K Feb  9 10:17 upsample_ispc_avx512skx.h
    -rw-rw-r-- 1 amir amir 1.8K Feb  9 10:17 upsample_ispc.h
    -rw-rw-r-- 1 amir amir 1.5K Feb  9 10:17 upsample_ispc_sse4.h
    drwxrwxr-x 2 amir amir 4.0K Feb  9 10:17 weights