Reputation: 1166
SITUATION
I tried to create a dll for my project, but idk what am i doing wrong.
1 Step : Create a shared Lib
I went to create new project
->
library
->
c++ library
->
added some test method that returns a const int
->
built Realse and Debug versions
2 Step : Add lib to my project
what i did is : right click on my 'real' project
->
clicked on add Library
->
clicked on 'external library' option
->
in 'library path' section browsed to my .so file
->
Qt added auto-generated code to my .pro file
PROBLEM
i can NOT access to my header in my library.
here is my main.cpp
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include "StickyNotesCore.h" // <- says error: file not found
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
const QUrl url(QStringLiteral("qrc:/main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
}, Qt::QueuedConnection);
engine.load(url);
return app.exec();
}
my stickynotescore.h
#ifndef STICKYNOTESCORE_H
#define STICKYNOTESCORE_H
#include "stickynotescore_global.h"
class STICKYNOTESCORESHARED_EXPORT StickyNotesCore
{
public:
StickyNotesCore();
int Test();
};
#endif // STICKYNOTESCORE_H
my StickyNotes.pro
QT += quick
CONFIG += c++11
# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Refer to the documentation for the
# deprecated API to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if it uses 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
SOURCES += \
main.cpp
RESOURCES += qml.qrc
# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =
# Additional import path used to resolve QML modules just for Qt Quick Designer
QML_DESIGNER_IMPORT_PATH =
QT_QUICK_CONTROLS_STYLE=material ./app
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../build-StickyNotesCore-Desktop_Qt_5_13_0_GCC_64bit-Debug/release/ -lStickyNotesCore
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../build-StickyNotesCore-Desktop_Qt_5_13_0_GCC_64bit-Debug/debug/ -lStickyNotesCore
else:unix: LIBS += -L$$PWD/../build-StickyNotesCore-Desktop_Qt_5_13_0_GCC_64bit-Debug/ -lStickyNotesCore
INCLUDEPATH += $$PWD/../build-StickyNotesCore-Desktop_Qt_5_13_0_GCC_64bit-Debug
DEPENDPATH += $$PWD/../build-StickyNotesCore-Desktop_Qt_5_13_0_GCC_64bit-Debug
EDIT
Folder tree
Upvotes: 0
Views: 288
Reputation: 1585
For your .pro file replace INCLUDEPATH ad DEPENDEPATH to the path where the .h files for your library is located.
make sure to run qmake
after make the changes.
INCLUDEPATH += $$PWD/../build-StickyNotesCore-Desktop_Qt_5_13_0_GCC_64bit-Debug
DEPENDPATH += $$PWD/../build-StickyNotesCore-Desktop_Qt_5_13_0_GCC_64bit-Debug
Here is an example of what i on my .pro file.
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../../../mylibrary/lib/vc140/x64/ -lMYLIBRARY
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../../../mylibrary/lib/vc140/x64/ -lMYLIBRARYd
else:unix: LIBS += -L$$PWD/../../../../../mylibrary/lib/vc140/Win32/ -lMYLIBRARY
INCLUDEPATH += $$PWD/../../../../../mylibrary/include
DEPENDPATH += $$PWD/../../../../../mylibrary/include
Upvotes: 1