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. Cannot recognize header .h file from external dynamic library
Forum Updated to NodeBB v4.3 + New Features

Cannot recognize header .h file from external dynamic library

Scheduled Pinned Locked Moved Unsolved General and Desktop
19 Posts 3 Posters 1.2k Views 2 Watching
  • 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.
  • I Offline
    I Offline
    ItzMeJP
    wrote on 16 Jun 2021, 17:32 last edited by
    #1

    Hello,

    I developed an API and exported it as a dynamic library (".so" extension called mimic_grasping_server). Now I am designing a QT GUI interface and I added the lib in my ".pro" file as follow:

    QT       += core gui
    QT += 3dcore 3drender 3dinput 3dextras
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    CONFIG += c++11
    
    # You can make your code fail to compile if it uses deprecated APIs.
    # In order to do so, uncomment the following line.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    
    SRC_FOLDER = $$PWD/src
    INCLUDE_FOLDER = $$PWD/include
    FORMS_FOLDER = $$PWD/forms
    
    #External libs
    unix|win32: LIBS += -lboost_thread
    unix|win32: LIBS += -L$$PWD/libs/ -lmimic_grasping_server
    
    INCLUDEPATH += $$PWD/libs
    DEPENDPATH += $$PWD/libs
    
    SOURCES += \
        $$SRC_FOLDER/main.cpp \
        $$SRC_FOLDER/mainwindow.cpp \
        $$SRC_FOLDER/meshentity.cpp \
        $$SRC_FOLDER/toolfirmwarewindow.cpp \
        $$SRC_FOLDER/visualization3d.cpp \
        $$SRC_FOLDER/localizationwindow.cpp \
    
    HEADERS += \
        $$INCLUDE_FOLDER/mainwindow.h \
        $$INCLUDE_FOLDER/meshentity.h \
        $$INCLUDE_FOLDER/toolfirmwarewindow.h \
        $$INCLUDE_FOLDER/visualization3d.h \
        $$INCLUDE_FOLDER/localizationwindow.h \
    
    FORMS += \
        $$FORMS_FOLDER/mainwindow.ui \
        $$FORMS_FOLDER/configurations/toolfirmwarewindow.ui \
        $$FORMS_FOLDER/configurations/localizationwindow.ui \
    
    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target
    
    

    The code compiles well, however, I cannot include the header in mainwindow.h. Qt cannot find the header definition so a can include into the code, such as #include <mimic_grasping_server/mimic_grasping_server.h>.

    Anyone could help me with that?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 16 Jun 2021, 17:33 last edited by
      #2

      Hi,

      Where is that header located with regard to your project ?

      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
      1
      • I Offline
        I Offline
        ItzMeJP
        wrote on 16 Jun 2021, 17:44 last edited by
        #3

        The is my directory tree

        mimic_grasping_gui/
        ├─ mimic_grasping_gui.pro
        ├─ forms/
        │ ├─ mainwindow.ui
        │ ├─ [...]
        ├─ include/
        │ ├─ mainwindow.h
        │ ├─ [...]
        ├─ libs/
        │ ├─ libmimic_grasping_server.so
        ├─ src/
        │ ├─main.cpp
        │ ├─ [...]

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 16 Jun 2021, 17:45 last edited by
          #4

          @ItzMeJP said in Cannot recognize header .h file from external dynamic library:

          mimic_grasping_server.h

          You did not say where exactly that file is.

          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
          1
          • J Offline
            J Offline
            JoeCFD
            wrote on 16 Jun 2021, 17:49 last edited by JoeCFD
            #5

            @ItzMeJP said in Cannot recognize header .h file from external dynamic library:

            INCLUDE_FOLDER

            From INCLUDEPATH += $$PWD/libs, it can be assumed that the header files are in $$PWD/libs.
            I guess you may do this
            #include "mimic_grasping_server.h"

            I 1 Reply Last reply 16 Jun 2021, 18:04
            0
            • I Offline
              I Offline
              ItzMeJP
              wrote on 16 Jun 2021, 17:54 last edited by ItzMeJP
              #6

              @SGaist I would like to include the header file from the dynamic lib (i.e. lmimic_grasping_server).

              It should be <mimic_grasping_server/mimic_grasping_server.h>. Is there any other way to perform this include?

              My dynamic lib was created by using the CMAKE file below:

              cmake_minimum_required(VERSION 3.19)
              project(mimic_grasping_server
                      VERSION 16.06.2021
                      DESCRIPTION
                      "Mimic grasping server API to C++")
              
              set(CMAKE_CXX_STANDARD 17)
              set(SUBDIR_LIBS_PATH libs)
              
              #External packages
              find_package(Eigen3 REQUIRED) # To matrix operations
              find_package(Boost REQUIRED COMPONENTS system thread timer) # Multithreading
              
              #Static Libs subdirectories
              add_subdirectory(${SUBDIR_LIBS_PATH}/SimpleSerialInterface)
              set(SIMPLE_SERIAL_INCLUDE_DIR libs/SimpleSerialInterface/include/)
              
              ## Specify additional locations of header files
              ## Your package locations should be listed before other locations
              include_directories(
                      include
                      ${SIMPLE_SERIAL_INCLUDE_DIR}
                      ${Eigen3_INCLUDE_DIRS}
                      ${BOOST_INCLUDE_DIRS}
              )
              
              ## Declare a C++ library
              add_library(mimic_grasping_server SHARED
                          src/mimic_grasping_server.cpp
                          src/tool_firmware_interface.cpp
                      )
              
              set_target_properties(mimic_grasping_server PROPERTIES
                      VERSION ${PROJECT_VERSION}
                      SOVERSION 0
                      )
              
              ## Set dependencies of the library
              target_link_libraries(mimic_grasping_server
                      simple_serial
                      ${BOOST_LIBRARIES}
                      ${CMAKE_THREAD_LIBS_INIT}
                      ${EIGEN_LIBRARIES}
                      Boost::thread
                      Boost::timer
                      jsoncpp
                      )
              
              
              
              1 Reply Last reply
              0
              • J JoeCFD
                16 Jun 2021, 17:49

                @ItzMeJP said in Cannot recognize header .h file from external dynamic library:

                INCLUDE_FOLDER

                From INCLUDEPATH += $$PWD/libs, it can be assumed that the header files are in $$PWD/libs.
                I guess you may do this
                #include "mimic_grasping_server.h"

                I Offline
                I Offline
                ItzMeJP
                wrote on 16 Jun 2021, 18:04 last edited by
                #7

                @JoeCFD said in Cannot recognize header .h file from external dynamic library:

                @ItzMeJP said in Cannot recognize header .h file from external dynamic library:

                INCLUDE_FOLDER

                From INCLUDEPATH += $$PWD/libs, it can be assumed that the header files are in $$PWD/libs.
                I guess you may do this
                #include "mimic_grasping_server.h"

                @JoeCFD I already try this one, even though #include "mimic_grasping_server/mimic_grasping_server.h". None of these worked.

                J 1 Reply Last reply 16 Jun 2021, 18:22
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 16 Jun 2021, 18:12 last edited by
                  #8

                  At the risk of repeating myself: where is that header file located on your hard drive exactly ?

                  From your mimic_grasping_gui project structure, it does not seem to be in there, correct ?

                  If so, where exactly is it ? Depending on that answer, you'll have to adjust the INCLUDEPATH variable content.

                  By the way, why are you putting the library itself in your project sources ?

                  On an unrelated note, since you are already using cmake for your library, why not also for your GUI project ?

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

                  I 1 Reply Last reply 16 Jun 2021, 18:52
                  0
                  • I ItzMeJP
                    16 Jun 2021, 18:04

                    @JoeCFD said in Cannot recognize header .h file from external dynamic library:

                    @ItzMeJP said in Cannot recognize header .h file from external dynamic library:

                    INCLUDE_FOLDER

                    From INCLUDEPATH += $$PWD/libs, it can be assumed that the header files are in $$PWD/libs.
                    I guess you may do this
                    #include "mimic_grasping_server.h"

                    @JoeCFD I already try this one, even though #include "mimic_grasping_server/mimic_grasping_server.h". None of these worked.

                    J Offline
                    J Offline
                    JoeCFD
                    wrote on 16 Jun 2021, 18:22 last edited by
                    #9

                    @ItzMeJP List your Makefile here generated with .pro.

                    I 1 Reply Last reply 16 Jun 2021, 18:30
                    0
                    • J JoeCFD
                      16 Jun 2021, 18:22

                      @ItzMeJP List your Makefile here generated with .pro.

                      I Offline
                      I Offline
                      ItzMeJP
                      wrote on 16 Jun 2021, 18:30 last edited by
                      #10

                      @JoeCFD said in Cannot recognize header .h file from external dynamic library:

                      @ItzMeJP List your Makefile here generated with .pro.

                      Sorry I cannot upload the file here (not even attach the file). I do not have enough reputation and privileges. Thus I shared through this link:

                      https://drive.google.com/file/d/1VptBnHB0d_YPnofJUKMHfAWquP60sQBj/view?usp=sharing

                      1 Reply Last reply
                      0
                      • S SGaist
                        16 Jun 2021, 18:12

                        At the risk of repeating myself: where is that header file located on your hard drive exactly ?

                        From your mimic_grasping_gui project structure, it does not seem to be in there, correct ?

                        If so, where exactly is it ? Depending on that answer, you'll have to adjust the INCLUDEPATH variable content.

                        By the way, why are you putting the library itself in your project sources ?

                        On an unrelated note, since you are already using cmake for your library, why not also for your GUI project ?

                        I Offline
                        I Offline
                        ItzMeJP
                        wrote on 16 Jun 2021, 18:52 last edited by ItzMeJP
                        #11

                        @SGaist said in Cannot recognize header .h file from external dynamic library:

                        At the risk of repeating myself: where is that header file located on your hard drive exactly ?

                        There are no ".h". It is a dynamic lib import. Look at the case of Boost Thread lib. I added that as " unix|win32: LIBS += -lboost_thread " and the main code can recognize its include as "#include <boost/thread.hpp>"

                        From your mimic_grasping_gui project structure, it does not seem to be in there, correct ?

                        This is a folder to place all external APIs. Thus, when changing PC, I know exactly all .so prerequisites.

                        By the way, why are you putting the library itself in your project sources ?
                        On an unrelated note, since you are already using cmake for your library, why not also for your GUI project ?

                        I don't want to. My API is used in different systems and is programmed in pure C++. The GUI is just one of them.

                        J 1 Reply Last reply 16 Jun 2021, 19:11
                        0
                        • I ItzMeJP
                          16 Jun 2021, 18:52

                          @SGaist said in Cannot recognize header .h file from external dynamic library:

                          At the risk of repeating myself: where is that header file located on your hard drive exactly ?

                          There are no ".h". It is a dynamic lib import. Look at the case of Boost Thread lib. I added that as " unix|win32: LIBS += -lboost_thread " and the main code can recognize its include as "#include <boost/thread.hpp>"

                          From your mimic_grasping_gui project structure, it does not seem to be in there, correct ?

                          This is a folder to place all external APIs. Thus, when changing PC, I know exactly all .so prerequisites.

                          By the way, why are you putting the library itself in your project sources ?
                          On an unrelated note, since you are already using cmake for your library, why not also for your GUI project ?

                          I don't want to. My API is used in different systems and is programmed in pure C++. The GUI is just one of them.

                          J Offline
                          J Offline
                          JoeCFD
                          wrote on 16 Jun 2021, 19:11 last edited by JoeCFD
                          #12

                          @ItzMeJP
                          You are using relative path for include path.
                          INCPATH = -I../mimic_grasping_3 -I. -I../mimic_grasping_3/libs -I../../Qt/5.15.2/gcc_64/include

                          Your lib path is not. You make them consistent. You will be all right. Could be your PWD setting is not right.
                          LIBS = $(SUBLIBS) -lboost_thread -L/home/joaopedro/qt_ws/mimic_grasping_3/libs/ -lmimic_grasping_server /home/joaopedro/Qt/5.15.2/gcc_64/lib/libQt53DExtras.so /home/joaopedro/Qt/5.15.2/gcc_64/lib/libQt53DRender.so /home/joaopedro/Qt/5.15.2/gcc_64/lib/libQt53DInput.so /home/joaopedro/Qt/5.15.2/gcc_64/lib/libQt53DLogic.so /home/joaopedro/Qt/5.15.2/gcc_64/lib/libQt53DCore.so /home/joaopedro/Qt/5.15.2/gcc_64/lib/libQt5Gamepad.so /home/joaopedro/Qt/5.15.2/gcc_64/lib/libQt5Widgets.so /home/joaopedro/Qt/5.15.2/gcc_64/lib/libQt5Gui.so /home/joaopedro/Qt/5.15.2/gcc_64/lib/libQt5Network.so /home/joaopedro/Qt/5.15.2/gcc_64/lib/libQt5Core.so -lGL -lpthread

                          I 1 Reply Last reply 16 Jun 2021, 19:27
                          0
                          • J Offline
                            J Offline
                            JoeCFD
                            wrote on 16 Jun 2021, 19:27 last edited by
                            #13

                            INCLUDEPATH += $$absolute_path($$PWD)/libs
                            DEPENDPATH += $$absolute_path($$PWD)/libs

                            check your Makefile to see if it helps.

                            I 1 Reply Last reply 16 Jun 2021, 20:00
                            0
                            • J JoeCFD
                              16 Jun 2021, 19:11

                              @ItzMeJP
                              You are using relative path for include path.
                              INCPATH = -I../mimic_grasping_3 -I. -I../mimic_grasping_3/libs -I../../Qt/5.15.2/gcc_64/include

                              Your lib path is not. You make them consistent. You will be all right. Could be your PWD setting is not right.
                              LIBS = $(SUBLIBS) -lboost_thread -L/home/joaopedro/qt_ws/mimic_grasping_3/libs/ -lmimic_grasping_server /home/joaopedro/Qt/5.15.2/gcc_64/lib/libQt53DExtras.so /home/joaopedro/Qt/5.15.2/gcc_64/lib/libQt53DRender.so /home/joaopedro/Qt/5.15.2/gcc_64/lib/libQt53DInput.so /home/joaopedro/Qt/5.15.2/gcc_64/lib/libQt53DLogic.so /home/joaopedro/Qt/5.15.2/gcc_64/lib/libQt53DCore.so /home/joaopedro/Qt/5.15.2/gcc_64/lib/libQt5Gamepad.so /home/joaopedro/Qt/5.15.2/gcc_64/lib/libQt5Widgets.so /home/joaopedro/Qt/5.15.2/gcc_64/lib/libQt5Gui.so /home/joaopedro/Qt/5.15.2/gcc_64/lib/libQt5Network.so /home/joaopedro/Qt/5.15.2/gcc_64/lib/libQt5Core.so -lGL -lpthread

                              I Offline
                              I Offline
                              ItzMeJP
                              wrote on 16 Jun 2021, 19:27 last edited by
                              #14
                              This post is deleted!
                              1 Reply Last reply
                              0
                              • S Offline
                                S Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on 16 Jun 2021, 19:41 last edited by
                                #15

                                You had it working with boost because it has likely been installed using your system's package manager and if not, it's located in one of the default paths looked for by the compiler.

                                There's not automagical header include path discovery when you only provide the library.

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

                                I 1 Reply Last reply 16 Jun 2021, 20:11
                                1
                                • J JoeCFD
                                  16 Jun 2021, 19:27

                                  INCLUDEPATH += $$absolute_path($$PWD)/libs
                                  DEPENDPATH += $$absolute_path($$PWD)/libs

                                  check your Makefile to see if it helps.

                                  I Offline
                                  I Offline
                                  ItzMeJP
                                  wrote on 16 Jun 2021, 20:00 last edited by
                                  #16

                                  @JoeCFD No, it does not help. The MakeFile still the same...

                                  1 Reply Last reply
                                  0
                                  • S SGaist
                                    16 Jun 2021, 19:41

                                    You had it working with boost because it has likely been installed using your system's package manager and if not, it's located in one of the default paths looked for by the compiler.

                                    There's not automagical header include path discovery when you only provide the library.

                                    I Offline
                                    I Offline
                                    ItzMeJP
                                    wrote on 16 Jun 2021, 20:11 last edited by
                                    #17

                                    @SGaist said in Cannot recognize header .h file from external dynamic library:

                                    You had it working with boost because it has likely been installed using your system's package manager and if not, it's located in one of the default paths looked for by the compiler.

                                    There's not automagical header include path discovery when you only provide the library.

                                    Thus, what is the recommended procedure to generate the dynamic lib and import it to Qt?

                                    1 Reply Last reply
                                    0
                                    • S Offline
                                      S Offline
                                      SGaist
                                      Lifetime Qt Champion
                                      wrote on 16 Jun 2021, 20:13 last edited by
                                      #18

                                      There's nothing special.

                                      Every library has a set of one or more headers they provide along the library file itself.

                                      There are standard locations to put them and if yours is not in one of them then you simply have to add the path to them to INCLUDEPATH.

                                      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
                                      1
                                      • J Offline
                                        J Offline
                                        JoeCFD
                                        wrote on 16 Jun 2021, 20:22 last edited by
                                        #19

                                        replace -I../mimic_grasping_3/libs of INCPATH in Makefile with -I/home/joaopedro/qt_ws/mimic_grasping_3/libs manually. Save it and then run make to see if it works.
                                        if not, run
                                        locate mimic_grasping_server.h
                                        to see where the file is located.

                                        1 Reply Last reply
                                        0

                                        1/19

                                        16 Jun 2021, 17:32

                                        • Login

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