What's the current way to handle linking Qt as a dll to my native C++ app?
-
I'm trying just to load in the libs into my C++ project but can't seem to do it, please help me out, it's been a few days of banging my head on the wall:
#include <QtCore\QLibrary> // #include <QtWidgets\QWidget> int main() { QLibrary myLibrary("./lib/mylib-frontend.dll");properties.json
{ "configurations": [ { "name": "Win32", "includePath": [ "${default}", "C:/Qt/6.5.1/msvc2019_64/include", "${workspaceFolder}/lib" ], "defines": [ "_DEBUG", "UNICODE", "_UNICODE" ], "windowsSdkVersion": "10.0.22000.0", "cStandard": "c17", "cppStandard": "c++17", "intelliSenseMode": "windows-msvc-x64" } ], "version": 4 }tasks.json:
{ "tasks": [ { "type": "cppbuild", "label": "C/C++: gcc.exe build active file", "command": "C:\\msys64\\mingw64\\bin\\gcc.exe", "args": [ "-I", "C:/Qt/6.5.1/msvc2019_64/include", "-fdiagnostics-color=always", "-g", "${file}", "-o", "${workspaceFolder}\\build\\${fileBasenameNoExtension}.exe", "-lstdc++", "-L C:/Qt/6.5.1/msvc2019_64/lib/ -lQt6Core" ], "options": { "cwd": "${fileDirname}" }, "problemMatcher": [ "$gcc" ], "group": { "kind": "build", "isDefault": true }, "detail": "Task generated by Debugger." } ], "version": "2.0.0" }Error:
Executing task: C/C++: gcc.exe build active file Starting build... C:\msys64\mingw64\bin\gcc.exe -I C:/Qt/6.5.1/msvc2019_64/include -fdiagnostics-color=always -g C:\Users\xxxxx\Documents\Development\Cpp\cpp-xxxxxa-frontend\src\main.cpp -o C:\Users\xxxxx\Documents\Development\Cpp\cpp-xxxxxa-frontend\build\main.exe -lstdc++ "-L C:/Qt/6.5.1/msvc2019_64/lib/ -lQt6Core" C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\xxxxx\AppData\Local\Temp\ccDqkaZL.o: in function `main': C:/Users/xxxxx/Documents/Development/Cpp/cpp-xxxxxa-frontend/src/main.cpp:5: undefined reference to `__imp__ZN8QLibraryC1ERK7QStringP7QObject' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/xxxxx/Documents/Development/Cpp/cpp-xxxxxa-frontend/src/main.cpp:52: undefined reference to `__imp__ZN8QLibraryD1Ev' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\xxxxx\AppData\Local\Temp\ccDqkaZL.o:C:/Qt/6.5.1/msvc2019_64/include/QtCore/qversiontagging.h:125: undefined reference to `__imp_qt_version_tag_6_5' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\xxxxx\AppData\Local\Temp\ccDqkaZL.o: in function `QString::QString(char const*)': C:/Qt/6.5.1/msvc2019_64/include/QtCore/qstring.h:1029: undefined reference to `__imp__ZN7QString8fromUtf8E14QByteArrayView' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\xxxxx\AppData\Local\Temp\ccDqkaZL.o: in function `QByteArrayView::QByteArrayView<char, true>(char const*, long long)': C:/Qt/6.5.1/msvc2019_64/include/QtCore/qbytearrayview.h:137: undefined reference to `__imp__Z9qt_assertPKcS0_i' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Qt/6.5.1/msvc2019_64/include/QtCore/qbytearrayview.h:137: undefined reference to `__imp__Z9qt_assertPKcS0_i' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\xxxxx\AppData\Local\Temp\ccDqkaZL.o: in function `QtPrivate::QPodArrayOps<char16_t>::destroyAll()': C:/Qt/6.5.1/msvc2019_64/include/QtCore/qarraydataops.h:95: undefined reference to `__imp__Z9qt_assertPKcS0_i' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Qt/6.5.1/msvc2019_64/include/QtCore/qarraydataops.h:96: undefined reference to `__imp__Z9qt_assertPKcS0_i' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\xxxxx\AppData\Local\Temp\ccDqkaZL.o: in function `QTypedArrayData<char16_t>::deallocate(QArrayData*)': C:/Qt/6.5.1/msvc2019_64/include/QtCore/qarraydata.h:124: undefined reference to `__imp__ZN10QArrayData10deallocateEPS_xx' collect2.exe: error: ld returned 1 exit status Build finished with error(s). -
I'm trying just to load in the libs into my C++ project but can't seem to do it, please help me out, it's been a few days of banging my head on the wall:
#include <QtCore\QLibrary> // #include <QtWidgets\QWidget> int main() { QLibrary myLibrary("./lib/mylib-frontend.dll");properties.json
{ "configurations": [ { "name": "Win32", "includePath": [ "${default}", "C:/Qt/6.5.1/msvc2019_64/include", "${workspaceFolder}/lib" ], "defines": [ "_DEBUG", "UNICODE", "_UNICODE" ], "windowsSdkVersion": "10.0.22000.0", "cStandard": "c17", "cppStandard": "c++17", "intelliSenseMode": "windows-msvc-x64" } ], "version": 4 }tasks.json:
{ "tasks": [ { "type": "cppbuild", "label": "C/C++: gcc.exe build active file", "command": "C:\\msys64\\mingw64\\bin\\gcc.exe", "args": [ "-I", "C:/Qt/6.5.1/msvc2019_64/include", "-fdiagnostics-color=always", "-g", "${file}", "-o", "${workspaceFolder}\\build\\${fileBasenameNoExtension}.exe", "-lstdc++", "-L C:/Qt/6.5.1/msvc2019_64/lib/ -lQt6Core" ], "options": { "cwd": "${fileDirname}" }, "problemMatcher": [ "$gcc" ], "group": { "kind": "build", "isDefault": true }, "detail": "Task generated by Debugger." } ], "version": "2.0.0" }Error:
Executing task: C/C++: gcc.exe build active file Starting build... C:\msys64\mingw64\bin\gcc.exe -I C:/Qt/6.5.1/msvc2019_64/include -fdiagnostics-color=always -g C:\Users\xxxxx\Documents\Development\Cpp\cpp-xxxxxa-frontend\src\main.cpp -o C:\Users\xxxxx\Documents\Development\Cpp\cpp-xxxxxa-frontend\build\main.exe -lstdc++ "-L C:/Qt/6.5.1/msvc2019_64/lib/ -lQt6Core" C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\xxxxx\AppData\Local\Temp\ccDqkaZL.o: in function `main': C:/Users/xxxxx/Documents/Development/Cpp/cpp-xxxxxa-frontend/src/main.cpp:5: undefined reference to `__imp__ZN8QLibraryC1ERK7QStringP7QObject' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/xxxxx/Documents/Development/Cpp/cpp-xxxxxa-frontend/src/main.cpp:52: undefined reference to `__imp__ZN8QLibraryD1Ev' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\xxxxx\AppData\Local\Temp\ccDqkaZL.o:C:/Qt/6.5.1/msvc2019_64/include/QtCore/qversiontagging.h:125: undefined reference to `__imp_qt_version_tag_6_5' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\xxxxx\AppData\Local\Temp\ccDqkaZL.o: in function `QString::QString(char const*)': C:/Qt/6.5.1/msvc2019_64/include/QtCore/qstring.h:1029: undefined reference to `__imp__ZN7QString8fromUtf8E14QByteArrayView' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\xxxxx\AppData\Local\Temp\ccDqkaZL.o: in function `QByteArrayView::QByteArrayView<char, true>(char const*, long long)': C:/Qt/6.5.1/msvc2019_64/include/QtCore/qbytearrayview.h:137: undefined reference to `__imp__Z9qt_assertPKcS0_i' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Qt/6.5.1/msvc2019_64/include/QtCore/qbytearrayview.h:137: undefined reference to `__imp__Z9qt_assertPKcS0_i' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\xxxxx\AppData\Local\Temp\ccDqkaZL.o: in function `QtPrivate::QPodArrayOps<char16_t>::destroyAll()': C:/Qt/6.5.1/msvc2019_64/include/QtCore/qarraydataops.h:95: undefined reference to `__imp__Z9qt_assertPKcS0_i' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Qt/6.5.1/msvc2019_64/include/QtCore/qarraydataops.h:96: undefined reference to `__imp__Z9qt_assertPKcS0_i' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\xxxxx\AppData\Local\Temp\ccDqkaZL.o: in function `QTypedArrayData<char16_t>::deallocate(QArrayData*)': C:/Qt/6.5.1/msvc2019_64/include/QtCore/qarraydata.h:124: undefined reference to `__imp__ZN10QArrayData10deallocateEPS_xx' collect2.exe: error: ld returned 1 exit status Build finished with error(s).@dogoooooo said in What's the current way to handle linking Qt as a dll to my native C++ app?:
I'm trying just to load in the libs into my C++ project but can't seem to do it, please help me out, it's been a few days of banging my head on the wall:
tasks.json:
{ "tasks": [ { "type": "cppbuild", "label": "C/C++: gcc.exe build active file", "command": "C:\\msys64\\mingw64\\bin\\gcc.exe", "args": [ "-I", "C:/Qt/6.5.1/msvc2019_64/include",It looks like this is attempting to use the MinGW compiler with libraries built for MSVC 2019. I believe that the two toolchains are incompatible.
-
@dogoooooo said in What's the current way to handle linking Qt as a dll to my native C++ app?:
I'm trying just to load in the libs into my C++ project but can't seem to do it, please help me out, it's been a few days of banging my head on the wall:
tasks.json:
{ "tasks": [ { "type": "cppbuild", "label": "C/C++: gcc.exe build active file", "command": "C:\\msys64\\mingw64\\bin\\gcc.exe", "args": [ "-I", "C:/Qt/6.5.1/msvc2019_64/include",It looks like this is attempting to use the MinGW compiler with libraries built for MSVC 2019. I believe that the two toolchains are incompatible.
Thanks so much, I swaped over to the wingw64, but getting issues still:
{ "tasks": [ { "type": "cppbuild", "label": "C/C++: gcc.exe build active file", "command": "C:/msys64/mingw64/bin/gcc.exe", "args": [ "-I", "C:/Qt/6.5.1/mingw_64/include", "-fdiagnostics-color=always", "-g", "${file}", "-o", "${workspaceFolder}\\build\\${fileBasenameNoExtension}.exe", "-lstdc++", "-L C:/Qt/6.5.1/mingw_64/lib/ -lQt6Core" ], "options": { "cwd": "${fileDirname}" }, "problemMatcher": [ "$gcc" ], "group": { "kind": "build", "isDefault": true }, "detail": "Task generated by Debugger." } ], "version": "2.0.0" }Starting build... C:/msys64/mingw64/bin/gcc.exe -I C:/Qt/6.5.1/mingw_64/include -fdiagnostics-color=always -g C:\Users\user\Documents\Development\Cpp\cpp-project-frontend\src\main.cpp -o C:\Users\user\Documents\Development\Cpp\cpp-project-frontend\build\main.exe -lstdc++ "-L C:/Qt/6.5.1/mingw_64/lib/ -lQt6Core" C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\user\AppData\Local\Temp\ccv1QKZq.o: in function `main': C:/Users/user/Documents/Development/Cpp/cpp-project-frontend/src/main.cpp:5: undefined reference to `__imp__ZN8QLibraryC1ERK7QStringP7QObject' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/user/Documents/Development/Cpp/cpp-project-frontend/src/main.cpp:52: undefined reference to `__imp__ZN8QLibraryD1Ev' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\user\AppData\Local\Temp\ccv1QKZq.o:C:/Qt/6.5.1/mingw_64/include/QtCore/qversiontagging.h:125: undefined reference to `__imp_qt_version_tag_6_5' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\user\AppData\Local\Temp\ccv1QKZq.o: in function `QString::QString(char const*)': C:/Qt/6.5.1/mingw_64/include/QtCore/qstring.h:1029: undefined reference to `__imp__ZN7QString8fromUtf8E14QByteArrayView' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\user\AppData\Local\Temp\ccv1QKZq.o: in function `QByteArrayView::QByteArrayView<char, true>(char const*, long long)': C:/Qt/6.5.1/mingw_64/include/QtCore/qbytearrayview.h:137: undefined reference to `__imp__Z9qt_assertPKcS0_i' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Qt/6.5.1/mingw_64/include/QtCore/qbytearrayview.h:137: undefined reference to `__imp__Z9qt_assertPKcS0_i' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\user\AppData\Local\Temp\ccv1QKZq.o: in function `QtPrivate::QPodArrayOps<char16_t>::destroyAll()': C:/Qt/6.5.1/mingw_64/include/QtCore/qarraydataops.h:95: undefined reference to `__imp__Z9qt_assertPKcS0_i' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Qt/6.5.1/mingw_64/include/QtCore/qarraydataops.h:96: undefined reference to `__imp__Z9qt_assertPKcS0_i' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\user\AppData\Local\Temp\ccv1QKZq.o: in function `QTypedArrayData<char16_t>::deallocate(QArrayData*)': C:/Qt/6.5.1/mingw_64/include/QtCore/qarraydata.h:124: undefined reference to `__imp__ZN10QArrayData10deallocateEPS_xx' collect2.exe: error: ld returned 1 exit status Build finished with error(s). -
Thanks so much, I swaped over to the wingw64, but getting issues still:
{ "tasks": [ { "type": "cppbuild", "label": "C/C++: gcc.exe build active file", "command": "C:/msys64/mingw64/bin/gcc.exe", "args": [ "-I", "C:/Qt/6.5.1/mingw_64/include", "-fdiagnostics-color=always", "-g", "${file}", "-o", "${workspaceFolder}\\build\\${fileBasenameNoExtension}.exe", "-lstdc++", "-L C:/Qt/6.5.1/mingw_64/lib/ -lQt6Core" ], "options": { "cwd": "${fileDirname}" }, "problemMatcher": [ "$gcc" ], "group": { "kind": "build", "isDefault": true }, "detail": "Task generated by Debugger." } ], "version": "2.0.0" }Starting build... C:/msys64/mingw64/bin/gcc.exe -I C:/Qt/6.5.1/mingw_64/include -fdiagnostics-color=always -g C:\Users\user\Documents\Development\Cpp\cpp-project-frontend\src\main.cpp -o C:\Users\user\Documents\Development\Cpp\cpp-project-frontend\build\main.exe -lstdc++ "-L C:/Qt/6.5.1/mingw_64/lib/ -lQt6Core" C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\user\AppData\Local\Temp\ccv1QKZq.o: in function `main': C:/Users/user/Documents/Development/Cpp/cpp-project-frontend/src/main.cpp:5: undefined reference to `__imp__ZN8QLibraryC1ERK7QStringP7QObject' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/user/Documents/Development/Cpp/cpp-project-frontend/src/main.cpp:52: undefined reference to `__imp__ZN8QLibraryD1Ev' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\user\AppData\Local\Temp\ccv1QKZq.o:C:/Qt/6.5.1/mingw_64/include/QtCore/qversiontagging.h:125: undefined reference to `__imp_qt_version_tag_6_5' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\user\AppData\Local\Temp\ccv1QKZq.o: in function `QString::QString(char const*)': C:/Qt/6.5.1/mingw_64/include/QtCore/qstring.h:1029: undefined reference to `__imp__ZN7QString8fromUtf8E14QByteArrayView' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\user\AppData\Local\Temp\ccv1QKZq.o: in function `QByteArrayView::QByteArrayView<char, true>(char const*, long long)': C:/Qt/6.5.1/mingw_64/include/QtCore/qbytearrayview.h:137: undefined reference to `__imp__Z9qt_assertPKcS0_i' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Qt/6.5.1/mingw_64/include/QtCore/qbytearrayview.h:137: undefined reference to `__imp__Z9qt_assertPKcS0_i' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\user\AppData\Local\Temp\ccv1QKZq.o: in function `QtPrivate::QPodArrayOps<char16_t>::destroyAll()': C:/Qt/6.5.1/mingw_64/include/QtCore/qarraydataops.h:95: undefined reference to `__imp__Z9qt_assertPKcS0_i' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Qt/6.5.1/mingw_64/include/QtCore/qarraydataops.h:96: undefined reference to `__imp__Z9qt_assertPKcS0_i' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\user\AppData\Local\Temp\ccv1QKZq.o: in function `QTypedArrayData<char16_t>::deallocate(QArrayData*)': C:/Qt/6.5.1/mingw_64/include/QtCore/qarraydata.h:124: undefined reference to `__imp__ZN10QArrayData10deallocateEPS_xx' collect2.exe: error: ld returned 1 exit status Build finished with error(s).@dogoooooo said in What's the current way to handle linking Qt as a dll to my native C++ app?:
I'm not sure what build tool is in use here, so maybe this is ok, but it looks like the library path (-L) and library link (-l) flags are being combined into a single argument. They probably need to be separated into individual quoted values separated by a comma.
[...] "-lstdc++", "-L C:/Qt/6.5.1/mingw_64/lib/ -lQt6Core"Starting build... C:/msys64/mingw64/bin/gcc.exe [...] -lstdc++ "-L C:/Qt/6.5.1/mingw_64/lib/ -lQt6Core" -
@dogoooooo said in What's the current way to handle linking Qt as a dll to my native C++ app?:
I'm not sure what build tool is in use here, so maybe this is ok, but it looks like the library path (-L) and library link (-l) flags are being combined into a single argument. They probably need to be separated into individual quoted values separated by a comma.
[...] "-lstdc++", "-L C:/Qt/6.5.1/mingw_64/lib/ -lQt6Core"Starting build... C:/msys64/mingw64/bin/gcc.exe [...] -lstdc++ "-L C:/Qt/6.5.1/mingw_64/lib/ -lQt6Core"@jeremy_k said in What's the current way to handle linking Qt as a dll to my native C++ app?:
They probably need to be separated into individual quoted values separated by a comma.
Good catch. Furthermore, there should be no space after
-L. -
@jeremy_k said in What's the current way to handle linking Qt as a dll to my native C++ app?:
They probably need to be separated into individual quoted values separated by a comma.
Good catch. Furthermore, there should be no space after
-L.@SimonSchroeder said in What's the current way to handle linking Qt as a dll to my native C++ app?:
Good catch. Furthermore, there should be no space after
-L.Separating -L and the link path seems to be fine. I don't see it mentioned explicitly in the documentation like the two variations of -l, but it has worked for a significant length of time. That may be a general allowance for -<option><value> arguments. It can even be necessary if relying on a shell to convert ~ to $HOME. ie:
g++ -L ~/Qt/5.15.2/gcc_64/lib -l Qt5Core a.cppworks.
g++ -L~/Qt/5.15.2/gcc_64/lib -l Qt5Core a.cppdoes not.