Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to link an external library in Qt Creator when LIBS += -L“…” and -l don't seem to work?
QtWS25 Last Chance

How to link an external library in Qt Creator when LIBS += -L“…” and -l don't seem to work?

Scheduled Pinned Locked Moved Solved General and Desktop
26 Posts 7 Posters 5.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    Warrior
    wrote on 8 Feb 2021, 17:41 last edited by
    #1

    I've been trying to use the https://github.com/OpenImageDenoise/oidn#compiling-on-linuxmacos library in my code on Linux but still have no luck as of now. Apparently it seems that I am not linking the library properly but the normal ways to link the library also do not seem to work.

    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 tried LIBS += -L oidn/build -lOpenImageDenoise but got the error message "cannot find -lOpenImageDenoise". 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.

    P J 2 Replies Last reply 8 Feb 2021, 18:06
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 8 Feb 2021, 17:52 last edited by
      #2

      Hi and welcome to devnet,

      Where did you install that library on your system ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • W Offline
        W Offline
        Warrior
        wrote on 8 Feb 2021, 18:01 last edited by Warrior 2 Aug 2021, 18:01
        #3

        I'm not sure what you mean by "install" but I followed the steps described in the Intel Open Image Denoise page (https://github.com/OpenImageDenoise/oidn#compiling-on-linuxmacos) to compile the package via cmake and make. I first cloned the OIDN repo somewhere outside my code directory (~/Desktop/pathtracer). Then after compilation I moved the oidn directory to ~/Desktop/pathtracer. You can see the directories below to get a better idea about the structure of my files:

        pathtracer directory:
        5f454b88-2a45-4927-836a-9d0b4a2dc485-image.png

        pathtracer/oidn directory:
        62d621c3-78dc-4f47-932c-ac1cc03c8103-image.png

        pathtracer/oidn/build directory:
        be3bfc9e-a89d-4433-bf0d-8e67739e26ef-image.png

        pathtracer/oidn/include directory:
        46a094ac-0d3c-4882-acc8-d1d53f82f3ba-image.png

        pathtracer/oidn/include/OpenImageDenoise directory (I'm supposed to use the .hpp file since I am using C++11:
        9e3367b4-3434-4334-b319-9544e5dc5753-image.png

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 8 Feb 2021, 18:05 last edited by
          #4

          Then you should use the full path to the folder containing your library in the -L statement of your Qt project as the current location is not part of any search paths used by the linker.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          W 2 Replies Last reply 8 Feb 2021, 18:12
          2
          • W Warrior
            8 Feb 2021, 17:41

            I've been trying to use the https://github.com/OpenImageDenoise/oidn#compiling-on-linuxmacos library in my code on Linux but still have no luck as of now. Apparently it seems that I am not linking the library properly but the normal ways to link the library also do not seem to work.

            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 tried LIBS += -L oidn/build -lOpenImageDenoise but got the error message "cannot find -lOpenImageDenoise". 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.

            P Offline
            P Offline
            Pablo J. Rogina
            wrote on 8 Feb 2021, 18:06 last edited by
            #5

            @Warrior said in How to link an external library in Qt Creator when LIBS += -L“…” and -l don't seem to work?:

            if someone can help me figure out what I need to do to get OIDN work.

            Have you already checked this article "Third Party Libraries"?

            In particular this line:

            LIBS += -L"3rdparty/CatWhisperer/lib" -lCatWhisperer
            

            In addition, you may want to consider installing/having the library "outside" your project, since what will happen if you need to create another different project (Qt app) using that same library? Are you going to duplicate the headers/.so files into the new project? I don't think so...

            Upvote the answer(s) that helped you solve the issue
            Use "Topic Tools" button to mark your post as Solved
            Add screenshots via postimage.org
            Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            2
            • S SGaist
              8 Feb 2021, 18:05

              Then you should use the full path to the folder containing your library in the -L statement of your Qt project as the current location is not part of any search paths used by the linker.

              W Offline
              W Offline
              Warrior
              wrote on 8 Feb 2021, 18:12 last edited by Warrior 2 Aug 2021, 18:13
              #6

              @SGaist I used the followings and still get the errors cannot find -lOpenImageDenoise or cannot find -loidn. Am I supposed to do something else?
              LIBS += -L "/home/Warrior/Desktop/pathtracer/oidn/build" -lOpenImageDenoise
              LIBS += -L "/home/Warrior/Desktop/pathtracer/oidn/build" -loidn

              1 Reply Last reply
              0
              • S SGaist
                8 Feb 2021, 18:05

                Then you should use the full path to the folder containing your library in the -L statement of your Qt project as the current location is not part of any search paths used by the linker.

                W Offline
                W Offline
                Warrior
                wrote on 8 Feb 2021, 18:35 last edited by
                #7

                @SGaist Also, how can I add the library paths to the search path you mentioned? Maybe that makes my life easier

                1 Reply Last reply
                0
                • W Warrior
                  8 Feb 2021, 17:41

                  I've been trying to use the https://github.com/OpenImageDenoise/oidn#compiling-on-linuxmacos library in my code on Linux but still have no luck as of now. Apparently it seems that I am not linking the library properly but the normal ways to link the library also do not seem to work.

                  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 tried LIBS += -L oidn/build -lOpenImageDenoise but got the error message "cannot find -lOpenImageDenoise". 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.

                  J Offline
                  J Offline
                  JonB
                  wrote on 8 Feb 2021, 18:52 last edited by
                  #8

                  @Warrior said in How to link an external library in Qt Creator when LIBS += -L“…” and -l don't seem to work?:

                  LIBS += -L"oidn/build/"

                  Although you say you started your -L like this and things still didn't work, why have you changed over to LIBS += -L oidn/build from then on always? I cannot test, but I see no evidence from man gcc that you can put a space between -L and the directory name, and no examples do. I'd start by removing it, in case....

                  W 1 Reply Last reply 8 Feb 2021, 19:26
                  1
                  • J JonB
                    8 Feb 2021, 18:52

                    @Warrior said in How to link an external library in Qt Creator when LIBS += -L“…” and -l don't seem to work?:

                    LIBS += -L"oidn/build/"

                    Although you say you started your -L like this and things still didn't work, why have you changed over to LIBS += -L oidn/build from then on always? I cannot test, but I see no evidence from man gcc that you can put a space between -L and the directory name, and no examples do. I'd start by removing it, in case....

                    W Offline
                    W Offline
                    Warrior
                    wrote on 8 Feb 2021, 19:26 last edited by
                    #9

                    @JonB Thanks for noticing this. I also tried with the following and still get the same error of cannot find -lOpenImageDenoise:
                    LIBS += -L"/home/Warrior/Desktop/pathtracer/oidn/build" -lOpenImageDenoise

                    Any other thoughts? :( This is really strange. I'm not sure what else I need to do.

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 8 Feb 2021, 19:34 last edited by
                      #10

                      Can your show your .pro file content ?

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      W 1 Reply Last reply 8 Feb 2021, 19:36
                      0
                      • S SGaist
                        8 Feb 2021, 19:34

                        Can your show your .pro file content ?

                        W Offline
                        W Offline
                        Warrior
                        wrote on 8 Feb 2021, 19:36 last edited by Warrior 2 Aug 2021, 19:37
                        #11

                        @SGaist Sure. There you go:

                        QT += gui
                        QT += xml
                        
                        CONFIG += c++11 console
                        CONFIG -= app_bundle
                        
                        # The following define makes your compiler emit warnings if you use
                        # any feature of Qt which as been marked deprecated (the exact warnings
                        # depend on your compiler). Please consult the documentation of the
                        # deprecated API in order to know how to port your code away from it.
                        DEFINES += QT_DEPRECATED_WARNINGS
                        
                        # You can also make your code fail to compile if you use deprecated APIs.
                        # In order to do so, uncomment the following line.
                        # You can also select to disable deprecated APIs only up to a certain version of Qt.
                        DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
                        
                        QMAKE_CXXFLAGS += -msse2
                        QMAKE_CXXFLAGS += -fopenmp
                        LIBS += -fopenmp
                        LIBS += -L"/home/Warrior/Desktop/pathtracer/oidn/build/" -lOpenImageDenoise
                        
                        
                        
                        SOURCES += main.cpp \
                            pathtracer.cpp \
                            scene/scene.cpp \
                            BVH/BBox.cpp \
                            BVH/BVH.cpp \
                            scene/camera.cpp \
                            scene/basiccamera.cpp \
                            util/CS123XmlSceneParser.cpp \
                            scene/shape/mesh.cpp \
                            scene/shape/triangle.cpp
                        
                        HEADERS += \
                            pathtracer.h \
                            scene/scene.h \
                            BVH/BBox.h \
                            BVH/BVH.h \
                            BVH/IntersectionInfo.h \
                            BVH/Log.h \
                            BVH/Object.h \
                            BVH/Ray.h \
                            BVH/Stopwatch.h \
                            scene/camera.h \
                            scene/basiccamera.h \
                            util/CS123Common.h \
                            util/CS123ISceneParser.h \
                            util/CS123SceneData.h \
                            util/CS123XmlSceneParser.h \
                            scene/shape/Sphere.h \
                            scene/shape/mesh.h \
                            scene/shape/triangle.h \
                            util/tiny_obj_loader.h \
                            BVH/vector3.h \
                            oidn/include/OpenImageDenoise/oidn.hpp \
                            oidn/include/OpenImageDenoise/config.h \
                            oidn/build/mkl-dnn/include/dnnl_config.h \
                        
                        INCLUDEPATH += "Eigen/"
                        INCLUDEPATH += "oidn/include/OpenImageDenoise"
                        INCLUDEPATH += "oidn/build/mkl-dnn/include/"
                        INCLUDEPATH += "/oidn/build/"
                        
                        DISTFILES += \
                            README.txt
                        
                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on 8 Feb 2021, 19:41 last edited by
                          #12

                          That is looking good...
                          Did you do a full rebuild after modifying these paths ?
                          Also, did you check that all the symlinks of libOpenImageDenoise are valid and pointing to valid files ?

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          W 1 Reply Last reply 8 Feb 2021, 19:58
                          2
                          • S SGaist
                            8 Feb 2021, 19:41

                            That is looking good...
                            Did you do a full rebuild after modifying these paths ?
                            Also, did you check that all the symlinks of libOpenImageDenoise are valid and pointing to valid files ?

                            W Offline
                            W Offline
                            Warrior
                            wrote on 8 Feb 2021, 19:58 last edited by
                            #13

                            @SGaist Yes I did do a clean compilation but got the same error. I did not however check the symlinks you mentioned. How can I do that?

                            jsulmJ 1 Reply Last reply 9 Feb 2021, 05:53
                            0
                            • W Warrior
                              8 Feb 2021, 19:58

                              @SGaist Yes I did do a clean compilation but got the same error. I did not however check the symlinks you mentioned. How can I do that?

                              jsulmJ Offline
                              jsulmJ Offline
                              jsulm
                              Lifetime Qt Champion
                              wrote on 9 Feb 2021, 05:53 last edited by
                              #14

                              @Warrior said in How to link an external library in Qt Creator when LIBS += -L“…” and -l don't seem to work?:

                              How can I do that?

                              ls -lh /home/Warrior/Desktop/pathtracer/oidn/build/
                              

                              What is the output of this command?

                              W 1 Reply Last reply 9 Feb 2021, 12:37
                              1
                              • jsulmJ jsulm
                                9 Feb 2021, 05:53

                                @Warrior said in How to link an external library in Qt Creator when LIBS += -L“…” and -l don't seem to work?:

                                How can I do that?

                                ls -lh /home/Warrior/Desktop/pathtracer/oidn/build/
                                

                                What is the output of this command?

                                W Offline
                                W Offline
                                Warrior
                                wrote on 9 Feb 2021, 12:37 last edited by
                                #15

                                @jsulm Apparently the files don't show up. Could it be because I cloned and built oidn in another directory first and then moved everything to the path where my program is? or is there a way to fix the symlink issue?

                                ls -lh /home/Warrior/Desktop/pathtracer/oidn/build/
                                total 160K
                                drwxrwxr-x 4 Warrior Warrior 4.0K Feb  4 00:09 apps
                                -rw-rw-r-- 1 Warrior Warrior  19K Feb  4 00:09 CMakeCache.txt
                                drwxrwxr-x 7 Warrior Warrior 4.0K Feb  4 00:09 CMakeFiles
                                -rw-rw-r-- 1 Warrior Warrior 6.5K Feb  4 00:09 cmake_install.cmake
                                drwxrwxr-x 3 Warrior Warrior 4.0K Feb  4 00:09 common
                                -rw-r--r-- 1 Warrior Warrior 3.6K Feb  4 00:09 CPackConfig.cmake
                                -rw-r--r-- 1 Warrior Warrior 4.0K Feb  4 00:09 CPackSourceConfig.cmake
                                -rw-rw-r-- 1 Warrior Warrior 103K Feb  4 00:09 Makefile
                                drwxrwxr-x 3 Warrior Warrior 4.0K Feb  4 00:08 mkl-dnn
                                -rw-r--r-- 1 Warrior Warrior 1.6K Feb  4 00:09 OpenImageDenoiseConfigVersion.cmake
                                
                                jsulmJ 2 Replies Last reply 9 Feb 2021, 12:39
                                0
                                • W Warrior
                                  9 Feb 2021, 12:37

                                  @jsulm Apparently the files don't show up. Could it be because I cloned and built oidn in another directory first and then moved everything to the path where my program is? or is there a way to fix the symlink issue?

                                  ls -lh /home/Warrior/Desktop/pathtracer/oidn/build/
                                  total 160K
                                  drwxrwxr-x 4 Warrior Warrior 4.0K Feb  4 00:09 apps
                                  -rw-rw-r-- 1 Warrior Warrior  19K Feb  4 00:09 CMakeCache.txt
                                  drwxrwxr-x 7 Warrior Warrior 4.0K Feb  4 00:09 CMakeFiles
                                  -rw-rw-r-- 1 Warrior Warrior 6.5K Feb  4 00:09 cmake_install.cmake
                                  drwxrwxr-x 3 Warrior Warrior 4.0K Feb  4 00:09 common
                                  -rw-r--r-- 1 Warrior Warrior 3.6K Feb  4 00:09 CPackConfig.cmake
                                  -rw-r--r-- 1 Warrior Warrior 4.0K Feb  4 00:09 CPackSourceConfig.cmake
                                  -rw-rw-r-- 1 Warrior Warrior 103K Feb  4 00:09 Makefile
                                  drwxrwxr-x 3 Warrior Warrior 4.0K Feb  4 00:08 mkl-dnn
                                  -rw-r--r-- 1 Warrior Warrior 1.6K Feb  4 00:09 OpenImageDenoiseConfigVersion.cmake
                                  
                                  jsulmJ Offline
                                  jsulmJ Offline
                                  jsulm
                                  Lifetime Qt Champion
                                  wrote on 9 Feb 2021, 12:39 last edited by
                                  #16
                                  This post is deleted!
                                  1 Reply Last reply
                                  0
                                  • W Warrior
                                    9 Feb 2021, 12:37

                                    @jsulm Apparently the files don't show up. Could it be because I cloned and built oidn in another directory first and then moved everything to the path where my program is? or is there a way to fix the symlink issue?

                                    ls -lh /home/Warrior/Desktop/pathtracer/oidn/build/
                                    total 160K
                                    drwxrwxr-x 4 Warrior Warrior 4.0K Feb  4 00:09 apps
                                    -rw-rw-r-- 1 Warrior Warrior  19K Feb  4 00:09 CMakeCache.txt
                                    drwxrwxr-x 7 Warrior Warrior 4.0K Feb  4 00:09 CMakeFiles
                                    -rw-rw-r-- 1 Warrior Warrior 6.5K Feb  4 00:09 cmake_install.cmake
                                    drwxrwxr-x 3 Warrior Warrior 4.0K Feb  4 00:09 common
                                    -rw-r--r-- 1 Warrior Warrior 3.6K Feb  4 00:09 CPackConfig.cmake
                                    -rw-r--r-- 1 Warrior Warrior 4.0K Feb  4 00:09 CPackSourceConfig.cmake
                                    -rw-rw-r-- 1 Warrior Warrior 103K Feb  4 00:09 Makefile
                                    drwxrwxr-x 3 Warrior Warrior 4.0K Feb  4 00:08 mkl-dnn
                                    -rw-r--r-- 1 Warrior Warrior 1.6K Feb  4 00:09 OpenImageDenoiseConfigVersion.cmake
                                    
                                    jsulmJ Offline
                                    jsulmJ Offline
                                    jsulm
                                    Lifetime Qt Champion
                                    wrote on 9 Feb 2021, 12:40 last edited by
                                    #17

                                    @Warrior said in How to link an external library in Qt Creator when LIBS += -L“…” and -l don't seem to work?:

                                    or is there a way to fix the symlink issue?

                                    Your current issue is not related to sym-links. Your problem is that the folder you pass via -L does NOT contain the libs. Either put them back to this folder or pass the folder containing the libs via -L.

                                    W 1 Reply Last reply 9 Feb 2021, 12:49
                                    2
                                    • jsulmJ jsulm
                                      9 Feb 2021, 12:40

                                      @Warrior said in How to link an external library in Qt Creator when LIBS += -L“…” and -l don't seem to work?:

                                      or is there a way to fix the symlink issue?

                                      Your current issue is not related to sym-links. Your problem is that the folder you pass via -L does NOT contain the libs. Either put them back to this folder or pass the folder containing the libs via -L.

                                      W Offline
                                      W Offline
                                      Warrior
                                      wrote on 9 Feb 2021, 12:49 last edited by
                                      #18

                                      @jsulm Well the folder definitely does contain the libs:

                                      05cb4e99-ce84-4bd3-96e2-80ec58d3d1c4-image.png

                                      J 1 Reply Last reply 9 Feb 2021, 12:55
                                      0
                                      • W Warrior
                                        9 Feb 2021, 12:49

                                        @jsulm Well the folder definitely does contain the libs:

                                        05cb4e99-ce84-4bd3-96e2-80ec58d3d1c4-image.png

                                        J Offline
                                        J Offline
                                        JonB
                                        wrote on 9 Feb 2021, 12:55 last edited by JonB 2 Sept 2021, 12:56
                                        #19

                                        @Warrior
                                        Well you can see for yourself that the listing from ls does not match the files/directories in your screenshot.

                                        My guess is that screenshot does not come from navigating to the same directory. (A screenshot from file manager without proof of what directory is showing is not much use.) So you need to look closely to sort this out....

                                        W 1 Reply Last reply 9 Feb 2021, 13:15
                                        3
                                        • J JonB
                                          9 Feb 2021, 12:55

                                          @Warrior
                                          Well you can see for yourself that the listing from ls does not match the files/directories in your screenshot.

                                          My guess is that screenshot does not come from navigating to the same directory. (A screenshot from file manager without proof of what directory is showing is not much use.) So you need to look closely to sort this out....

                                          W Offline
                                          W Offline
                                          Warrior
                                          wrote on 9 Feb 2021, 13:15 last edited by
                                          #20

                                          @JonB I totally understand the suspicious discrepancy between the screen shot and the directory listing but I am not trying to be funny and take people's time. They're both from the same path. I think I need to clone the oidn repo in the same directory where my code is and build it there. That can hopefully solve the problem.

                                          J 1 Reply Last reply 9 Feb 2021, 13:33
                                          0

                                          4/26

                                          8 Feb 2021, 18:05

                                          topic:navigator.unread, 22
                                          • Login

                                          • Login or register to search.
                                          4 out of 26
                                          • First post
                                            4/26
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved