The library is called mod.lib, I have used the following lines to link the library. I also include its header file. Not sure what is wrong, but it kept giving me the undefined reference errors of library's functions when I try to use them in the code.
win32: CONFIG (release, debug|release): LIBS += -LC:/Users/J/proj -lmod
INCLUDEPATH += C:/Users/J/proj
DEPENDPATH += C:/Users/J/proj
win32: PRE_TARGETDEPS += C:/Users/J/proj/mod.lib
Thanks for answering.
Use
LIBS += -L/C:/Users/J/proj -lmod
Instead of
LIBS += -LC:/Users/J/proj -lmod
The proper way for adding a library is
LIBS += -L/path/to -lyourmodule
Related
In my QtCreator C++ project I'm using subdirs template and have several subprojects including lib-project. In app-project I'm trying this:
win32:CONFIG(release, debug|release): LIBS += -L../Library/release -lLibrary
else:win32:CONFIG(debug, debug|release): LIBS += -L../Library/debug -lLibrary
else:unix: LIBS += -L../Library -lLibrary
On Linux it works well, but on Windows library compiles (there're .dll and .a files), linker links it (if I change the path to wrong, like -L../Library/debugg I have an error - can't find -lLibrary), but then I have "undefined reference to [my_classes]". INCLUDEPATH and DEPENDPATH are also correct (because it works on Linux):
INCLUDEPATH += $$PWD/.. $$PWD/../Library
DEPENDPATH += $$PWD/.. $$PWD/../Library
Also tried this:
LIBS += -L$$OUT_PWD/../Library/release -lLibrary
Same result, so what should I do?
I installed libfreenect. I opened QT and began to coding. When I use libfreenect.h no error occurres. But when I use libfreenect.hpp, this error occurred:"error: libusb.h: No such file or directory"
contents of .pro file is:
QT += core
QT -= gui
CONFIG += c++11
TARGET = 12moharram
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../usr/local/lib/release/ -lfreenect
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../usr/local/lib/debug/ -lfreenect
else:unix: LIBS += -L$$PWD/../../../usr/local/lib/ -lfreenect
INCLUDEPATH += $$PWD/../../../usr/local/include
DEPENDPATH += $$PWD/../../../usr/local/include
Where is the problem?
Probably libfreenect.h and libfreenect.hpp are themselves including other files, for a reason that I cannot understand libfreenect.hpp is including libusb.h and libfreenect.h is not. Probably libusb.h is not in your INCLUDEPATH.
I would first try to find libusb.h, if it is not present install it (you will probably have to install libusb-dev (debian style). Once you are sure libsub.h is present make sure is in the INCLUDEPATH, in case change the INCLUDEPATH in your .pro file.
This should fix this specific problem but after you fix this there can be more, good luck.
I have included the headers in Qt for my project, but the compiler is still not able to identify the headers. Libraries once included created its own includepath and depend.
Any help appriciated:
`INCLUDEPATH += $$PWD/../HDE/x86.linux/include
DEPENDPATH += $$PWD/../HDE/x86.linux/include
unix:!macx: LIBS += -L$$PWD/../HDE/x86.linux/lib/ -lddskernel
INCLUDEPATH += $$PWD/../HDE/x86.linux/include
DEPENDPATH += $$PWD/../HDE/x86.linux/include
unix:!macx: LIBS += -L$$PWD/../HDE/x86.linux/examples/dcps/Tutorial/cpp/standalone/ -lsacpp_tutorial_types
INCLUDEPATH += $$PWD/../HDE/x86.linux/examples/dcps/Tutorial/cpp/standalone
DEPENDPATH += $$PWD/../HDE/x86.linux/examples/dcps/Tutorial/cpp/standalone
unix:!macx: LIBS += -L$$PWD/../../../usr/lib/i386-linux-gnu/ -lpthread
INCLUDEPATH += $$PWD/../../../usr/lib/i386-linux-gnu
DEPENDPATH += $$PWD/../../../usr/lib/i386-linux-gnu`
All you have to do is also include the path for the header files in .pro file.
for instance if the header file is at location /home/jack/Myproject
then just write the below in the .pro file
INCLUDEPATH +=$$PWD/../Myproject
I'm using QT(5)-Creator with 2 projects, that compile both with MinGW my C++ programs under Windows 7. One project generates a static library, and the other is just there to verify that the library is alright.
The error:
When building the library no errors are generated and it creates successfully the static lib MyClassName.a.
In turn, when trying to import the library, I get error messages durring building/compilation:
undefined reference to 'MyClassName::MyClassName()'
undefined reference to 'MyClassName::MyClassFunction()'
The files:
here's the main.cpp of my importer project
#include <QCoreApplication>
#include "MyClassName.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
MyClassName *mainThread = new MyClassName();
mainThread->MyClassFunction();
return a.exec();
}
and it's .pro file
QT += core
QT += widgets
QT -= gui
TARGET = TESTerase
CONFIG += console
CONFIG -= app_bundle
CONFIG +=extserialport
CONFIG +=staticlib
TEMPLATE = app
HEADERS += \
MyClassName.h
SOURCES += main.cpp
unix:!macx: LIBS += -L$$PWD/../MyClassName-Release/ -lMyClassName
INCLUDEPATH += $$PWD
INCLUDEPATH += $$PWD/../MyClassName-Release/release
DEPENDPATH += $$PWD/../MyClassName-Release/release
unix:!macx: PRE_TARGETDEPS += $$PWD/../MyClassName-Release/release/MyClassName.a
btw I've used QT-Creator's include external library function
My guesses:
Since I'm able to [Strg+Click] the functions in the main, I assume the error is thrown by the Linker.
It may also be a manner of importing/creating/using libraries too, since I just started with that topic.
Anyways searching the Internet about it usually just results in the hint, to use the same compiler for both projects - which shouldn't matter in my case (since I'm building both projects with the same Creator and the same settings).
Has anybody an idea?
Thanks for your support
Kind Regards
[Update for Bogdans request]
the new .pro file
#-------------------------------------------------
#
# Project created by QtCreator 2015-04-29T19:46:22
#
#-------------------------------------------------
QT += core
QT += widgets
QT -= gui
TARGET = TESTerase
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG +=extserialport
HEADERS += \
MyClassName.h
SOURCES += main.cpp
unix:!macx: LIBS += -L$$PWD/../MyClassName-Release/ -lMyClassName
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../MyClassName-Release/release/ -lMyClassName
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../MyClassName-Release/debug/ -lMyClassName
else:unix:!macx: LIBS += -L$$PWD/../MyClassName-Release/ -lMyClassName
INCLUDEPATH += $$PWD/../MyClassName-Release/release
DEPENDPATH += $$PWD/../MyClassName-Release/release
win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../MyClassName-Release/release/MyClassName.a
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../MyClassName-Release/debug/MyClassName.a
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../MyClassName-Release/release/MyClassName.lib
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../MyClassName-Release/debug/MyClassName.lib
else:unix:!macx: PRE_TARGETDEPS += $$PWD/../MyClassName-Release/MyClassName.a
Your .pro file defines library dependencies only for unix platform unix:!macx:. I suppose there should be also win32 for Windows.
Had the same problem just now. Build was working fine on macOS/OSX but not on Windows with the same codebase.
It was caused by the fact I was not exporting my symbols, which is necessary on Windows.
Use Q_DECL_EXPORT on functions when building the lib.
And use Q_DECL_IMPORT when using the functions from the lib.
Example how to do this here: https://wiki.qt.io/How_to_create_a_library_with_Qt_and_use_it_in_an_application#Creating_a_shared_library
Solved the problem in my case, hope it helps!
what is the best way to add additional compiled libraries to my qt project ?
For example boost or poco libs ?
Thanks :)
If you're using the GCC compiler add something like this to the .pro file:
For Boost:
INCLUDEPATH += d:/Biblioteki/C++/boost/boost_1_44_0a
LIBPATH += d:/Biblioteki/C++/boost/boost_1_44_0a/stage/lib
LIBS += -lboost_system-mgw44-mt-d-1_44
LIBS += -lboost_filesystem-mgw44-mt-d-1_44
LIBS += -lboost_date_time-mgw44-mt-d-1_44
For Poco:
INCLUDEPATH += d:/Biblioteki/C++/Poco/poco-1.3.6p2-mingw-qt2/include
LIBPATH += d:/Biblioteki/C++/Poco/poco-1.3.6p2-mingw-qt2/lib
LIBS += -lPocoFoundationd
LIBS += -lPocoNetd
LIBS += -lPocoUtild
LIBS += -lPocoXML
INCLUDEPATH - is the location of directory with header files
LIBPATH - is the location of directory with *.a files
LIBS - contains list of libraries you want to use in your application