Unsolved Cannot recognize header .h file from external dynamic library
-
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?
-
Hi,
Where is that header located with regard to your project ?
-
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
│ ├─ [...] -
@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.
-
@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" -
@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 )
-
@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.
-
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 ?
-
@ItzMeJP List your Makefile here generated with .pro.
-
@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
-
@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.
-
@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/includeYour 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 -
INCLUDEPATH += $$absolute_path($$PWD)/libs
DEPENDPATH += $$absolute_path($$PWD)/libscheck your Makefile to see if it helps.
-
This post is deleted! -
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.
-
@JoeCFD No, it does not help. The MakeFile still the same...
-
@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?
-
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.
-
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.