Why Qt can't detect library from /usr/lib...
-
I created a library of my own and i install it using
sudo make install
And my library file successfully builds and copies at "/usr/lib". But when I include the library to another app of mine by
LIBS += -llibraryname
When building it says 'undefined reference to libraryFunction'. But if I do this
LIBS += -L/usr/lib -llibraryname
It got no error.
Please tell me why is this happens. -
Hi,
Run
gcc -print-search-dirs
, what do you get ? -
I found this...
install: /usr/lib/gcc/x86_64-linux-gnu/7/ programs: =/usr/lib/gcc/x86_64-linux-gnu/7/:/usr/lib/gcc/x86_64-linux-gnu/7/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/7/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../../x86_64-linux-gnu/bin/x86_64-linux-gnu/7/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../../x86_64-linux-gnu/bin/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../../x86_64-linux-gnu/bin/ libraries: =/usr/lib/gcc/x86_64-linux-gnu/7/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../../x86_64-linux-gnu/lib/x86_64-linux-gnu/7/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../../x86_64-linux-gnu/lib/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../../x86_64-linux-gnu/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/7/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../../lib/:/lib/x86_64-linux-gnu/7/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/7/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../../x86_64-linux-gnu/lib/:/usr/lib/gcc/x86_64-linux-gnu/7/../../../:/lib/:/usr/lib/
-
So as you can see,
/usr/lib/
is not in the search path list, hence you have to add it yourself to your projects. Nothing Qt specific here. -
You already know:
@Abrar said in Why Qt can't detect library from /usr/lib...:
LIBS += -L/usr/lib
That's the correct way.
-
What's the problem with that ?
An alternative for you is to set the
LIBRARY_PATH
environment variable. -
@JonB Actually there is no problem. But I just faced another issue that is I created another library and when I include that by -llibraryname that just builds fine...
And why is that. As one(my 2nd library) got the path but other(1st library) can't....
!!!
Please reply.... -
Where's that library located ?
How are you linking to it ?
Do you have any flags set for it that is not set for the first one ? -
@SGaist the 2nd library also installs at /usr/lib
And I just link it by typing
LIBS += -llibraryname
Like the 1st library.
But didn't add any more thing. And also I test two of them at once.
Is there any thing you can tell what is happening? -
As already asked, show your .pro file.
From what you wrote, you just added a new library to the list. So the folder was already added earlier.
-
#------------------------------------------------- # # Project created by QtCreator 2018-08-20T09:12:54 # #------------------------------------------------- QT += core gui widgets TARGET = help TEMPLATE = app # library for theme unix:!macx: LIBS += -lcprime unix:!macx: LIBS += -lcsys SOURCES += \ main.cpp \ help.cpp HEADERS += \ help.h FORMS += \ help.ui RESOURCES += \ icons.qrc # Disable warnings, enable threading support and c++11 CONFIG += thread silent build_all c++11 # Disable Debug on Release # CONFIG(release):DEFINES += QT_NO_DEBUG_OUTPUT # Build location BUILD_PREFIX = $$(CA_BUILD_DIR) isEmpty( BUILD_PREFIX ) { BUILD_PREFIX = ./build } MOC_DIR = $$BUILD_PREFIX/moc-qt5 OBJECTS_DIR = $$BUILD_PREFIX/obj-qt5 RCC_DIR = $$BUILD_PREFIX/qrc-qt5 UI_DIR = $$BUILD_PREFIX/uic-qt5 unix { isEmpty(PREFIX) { PREFIX = /usr } BINDIR = $$PREFIX/bin target.path = $$BINDIR desktop.path = $$PREFIX/share/applications/ desktop.files = "Help CoreApps.desktop" icons.path = $$PREFIX/share/coreapps/icons/ icons.files = icons/Help.svg INSTALLS += target icons desktop } DEFINES += QT_DEPRECATED_WARNINGS DEFINES += "HAVE_POSIX_OPENPT"
This is the .pro file of my application.
And my 1st libraryQT += widgets core network gui charts concurrent dbus TARGET = csys TEMPLATE = lib # disable all build warnings CONFIG += silent warn_on static # Disable Debug on Release #CONFIG(release):DEFINES += QT_NO_DEBUG_OUTPUT VERSION = 1.0.10 DEFINES += LIBCSYS_LIBRARY HEADERS += \ csys/cpu_info.h \ csys/disk_info.h \ csys/memory_info.h \ csys/network_info.h \ csys/process.h \ csys/process_info.h \ csys/system_info.h \ csys/command_util.h \ csys/file_util.h \ csys/format_util.h \ csys/battery.h \ csys/info_manager.h \ csys/upower.h \ csys/udisks2.h \ libcsys_global.h SOURCES += \ csys/cpu_info.cpp \ csys/disk_info.cpp \ csys/memory_info.cpp \ csys/network_info.cpp \ csys/process.cpp \ csys/process_info.cpp \ csys/system_info.cpp \ csys/command_util.cpp \ csys/file_util.cpp \ csys/format_util.cpp \ csys/battery.cpp \ csys/info_manager.cpp \ csys/upower.cpp \ csys/udisks2.cpp MOC_DIR = ../build/moc OBJECTS_DIR = ../build/obj RCC_DIR = ../build/qrc UI_DIR = ../build/uic unix { isEmpty(PREFIX) { PREFIX = /usr } INSTALLS += target includes CONFIG += create_pc no_install_prl link_pkgconfig contains(DEFINES, LIB64): target.path = $$INSTALL_PREFIX/lib64 else: target.path = $$INSTALL_PREFIX/lib target.path = $$PREFIX/lib/ includes.files = libcsys_global.h csys/*.h includes.path = $$PREFIX/include/csys QMAKE_PKGCONFIG_NAME = libcsys QMAKE_PKGCONFIG_DESCRIPTION = Library for coreapps QMAKE_PKGCONFIG_PREFIX = $$INSTALL_PREFIX QMAKE_PKGCONFIG_LIBDIR = $$target.path QMAKE_PKGCONFIG_INCDIR = $$includes.path QMAKE_PKGCONFIG_VERSION = $$VERSION QMAKE_PKGCONFIG_DESTDIR = pkgconfig }
And 2nd Library is
QT += widgets core gui TARGET = cprime TEMPLATE = lib # disable all build warnings CONFIG += silent warn_on thread silent build_all c++11 DEFINES += LIBCPRIME_LIBRARY INCLUDEPATH += ./cprime/ DEPENDPATH += ./cprime/ # Disable Debug on Release #CONFIG(release):DEFINES += QT_NO_DEBUG_OUTPUT VERSION = 1.1.1 DEFINES += LIBCPRIME_LIBRARY MOC_DIR = ../build/moc OBJECTS_DIR = ../build/obj RCC_DIR = ../build/qrc UI_DIR = ../build/uic unix { isEmpty(PREFIX) { PREFIX = /usr } INSTALLS += target includes data themefiles CONFIG += create_pc no_install_prl link_pkgconfig contains(DEFINES, LIB64): target.path = $$INSTALL_PREFIX/lib64 else: target.path = $$INSTALL_PREFIX/lib target.path = $$PREFIX/lib/ includes.files = cprime/*.h libcprime_global.h includes.path = $$PREFIX/include/cprime/ data.path = $$PREFIX/share/coreapps/docs data.files = docs/Changelog docs/LICENSE docs/To-Do.txt themefiles.path = $$PREFIX/share/coreapps/Theme themefiles.files = style/*.qss style/*.ini QMAKE_PKGCONFIG_NAME = libcprime QMAKE_PKGCONFIG_DESCRIPTION = Library for coreapps QMAKE_PKGCONFIG_PREFIX = $$INSTALL_PREFIX QMAKE_PKGCONFIG_LIBDIR = $$target.path QMAKE_PKGCONFIG_INCDIR = $$includes.path QMAKE_PKGCONFIG_VERSION = $$VERSION QMAKE_PKGCONFIG_DESTDIR = pkgconfig } HEADERS += \ cprime/globalfunctions.h \ cprime/utilities.h \ cprime/settingsmanage.h \ cprime/bookmarkmanage.h \ cprime/bookmarkdialog.h \ libcprime_global.h \ SOURCES += \ cprime/globalfunctions.cpp \ cprime/utilities.cpp \ cprime/settingsmanage.cpp \ cprime/bookmarkmanage.cpp \ cprime/bookmarkdialog.cpp FORMS += \ cprime/bookmarkdialog.ui
-
Did you check whether you have these libraires in multiple places on your system ?