Spdlog library can't open in the Qt.
-
I added spdlog.lib and fmt.lib to .pro file . And I also compiled the program but it's crashed.
How can I solve the problem?13:34:08: Starting C:\Users\enesa\Desktop\projeler\build-GaziStation-Desktop_Qt_5_15_2_MSVC2019_64bit-Debug\debug\GaziStation.exe ... 13:34:08: The program has unexpectedly finished. 13:34:08: The process was ended forcefully. 13:34:08: C:\Users\enesa\Desktop\projeler\build-GaziStation-Desktop_Qt_5_15_2_MSVC2019_64bit-Debug\debug\GaziStation.exe crashed.
#----------------------------------------------------------------------------------------- # Make options #----------------------------------------------------------------------------------------- UI_DIR = uic MOC_DIR = moc RCC_DIR = qrc OBJECTS_DIR = obj CONFIG += c++11 isEmpty(PREFIX) { PREFIX = /usr } TEMPLATE = app # Project template QT += xml QT += sql QT += svg QT += core QT += quick QT += charts QT += widgets QT += serialport QT += printsupport QT += quickcontrols2 ##- spdlog installed by default c:/dev/vcpkg SPDLOG_ROOT = c:/dev/vcpkg/installed/x64-windows exists($$SPDLOG_ROOT) { LIBS += -L$$SPDLOG_ROOT/lib -lspdlog -lfmt INCLUDEPATH += $$SPDLOG_ROOT/include DEPENDPATH += $$SPDLOG_ROOT/include DESTDIR_WIN = $$replace(DESTDIR, "/", "\\") SPDLOG_ROOT_WIN = $$replace(SPDLOG_ROOT, "/", "\\") } # 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 INCLUDEPATH += src SOURCES += \ main.cpp \ src/comm/network.cpp \ src/comm/packet.cpp \ src/comm/serialport.cpp \ src/controllers/mastercontroller.cpp RESOURCES += qml.qrc \ assets.qrc \ components.qrc # Additional import path used to resolve QML modules in Qt Creator's code model QML_IMPORT_PATH = $$PWD # Additional import path used to resolve QML modules just for Qt Quick Designer QML_DESIGNER_IMPORT_PATH = # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target HEADERS += \ src/comm/network.h \ src/comm/packet.h \ src/comm/serialport.h \ src/controllers/navigationcontroller.h \ src/controllers/mastercontroller.h !build_pass:message(GaziStation project dir: $${PWD})
#include <QGuiApplication> #include <QQmlApplicationEngine> #include <QQmlContext> #include "spdlog/spdlog.h" int main(int argc, char *argv[]) { #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); #endif QGuiApplication app(argc, argv); spdlog::info("...."); QQmlApplicationEngine engine; engine.addImportPath("qrc:/"); const QUrl url(QStringLiteral("qrc:/views/MasterView.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(); }
-
@Enes-Alp said in Spdlog library can't open in the Qt.:
The problem is in the spdlog::info function line
Have you tried the header-only approach?
-
@Enes-Alp said in Spdlog library can't open in the Qt.:
Did you try to start it in debug mode with Qt Creator?
I guess theconnect()
statement is what will stop your application.QObject::connect(
&engine, &QQmlApplicationEngine::objectCreated, &app,
[url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
},
Qt::QueuedConnection);Why do you check url? The interesting parameter is
obj
. Whenobj
is null, the instance could not be created. -
@Enes-Alp said in Spdlog library can't open in the Qt.:
I'm using msvc2019-64bit but when I changed the mingw, I get some linker error.
If you change Qt Kit from MSVC2019-64bit to mingw, you also have to use a compatible spdlog and fmt build version.
I guess the problem is in the QML code / import path.
Try to set the environment variableQML_IMPORT_TRACE
to got QML traces.
You can do it in code, like this:int main(int argc, char *argv[]) { #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); #endif qputenv("QML_IMPORT_TRACE", "1"); QGuiApplication app(argc, argv); QQmlApplicationEngine engine; engine.addImportPath("qrc:/"); const QUrl url(QStringLiteral("qrc:/views/MasterView.qml")); engine.load(url); return app.exec(); }
-
I installed with vcpkg like this
./vcpkg.exe install spdlog:x64-windows
. I didn't compile because thespdlog
has static compilation files(spdlog.lib, fmt.lib). I added just include and .lib files.##- spdlog installed by default c:/dev/vcpkg SPDLOG_ROOT = c:/dev/vcpkg/installed/x64-windows exists($$SPDLOG_ROOT) { LIBS += -L$$SPDLOG_ROOT/lib -lspdlog -lfmt INCLUDEPATH += $$SPDLOG_ROOT/include DEPENDPATH += $$SPDLOG_ROOT/include DESTDIR_WIN = $$replace(DESTDIR, "/", "\\") SPDLOG_ROOT_WIN = $$replace(SPDLOG_ROOT, "/", "\\") }
-
Hi,
Are you sure that these libs are static ? A .lib file can either be a static library or import library that will require the use of a dll at run time.
-
Then start your application through the debugger to get a stack trace of the crash.
-
@SGaist said in Spdlog library can't open in the Qt.:
Are you sure that these libs are static ? A .lib file can either be a static library or import library that will require the use of a dll at run time.
The spdlog library is either header-only or static.
-
Do you have it working if you copy the code of the examples in the library documentation (without any Qt stuff) ?
-
@Enes-Alp said in Spdlog library can't open in the Qt.:
The problem is in the spdlog::info function line
Have you tried the header-only approach?
-
Yes, I tried but I get the same result.
#include <spdlog/spdlog.h> int main() { spdlog::info("Welcome to spdlog"); return 0; }
QT -= gui CONFIG += c++11 console CONFIG -= app_bundle ##- spdlog installed by default c:/dev/vcpkg SPDLOG_ROOT = c:/dev/vcpkg/installed/x64-windows exists($$SPDLOG_ROOT) { LIBS += -L$$SPDLOG_ROOT/lib -lspdlog -lfmt INCLUDEPATH += $$SPDLOG_ROOT/include DEPENDPATH += $$SPDLOG_ROOT/include DESTDIR_WIN = $$replace(DESTDIR, "/", "\\") SPDLOG_ROOT_WIN = $$replace(SPDLOG_ROOT, "/", "\\") } # 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 SOURCES += \ main.cpp # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target `
-
@Enes-Alp said in Spdlog library can't open in the Qt.:
Yes, I tried but I get the same result.
But you don't have change anything, so the result will still be the same.
Header only approach means you add each spdlog header file inINCLUDES
and removespdlog
fromLIBS
. -
The concept of header only librairies is that you do not have anything to link.
-
The header only library means that you do not have to link anything but this means that you will build everything you use from it on each build.