I'm attempting to build an application with QTCreator on Windows10 that uses the QVTKWidget, but I get linker error(s):
mainwindow.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl QVTKWidget::QVTKWidget(class QWidget *,class QFlags<enum Qt::WindowType>)" referenced in function "public: void __cdecl Ui_MainWindow::setupUi(class QMainWindow *)"
I've downloaded Qt5.5 for msvc2013 and msvc2013_64. I've downloaded VTK7, and built it with Qt support using CMake. I built a vtk32 and vtk64. I've copied D:\VTK\vtk32\bin\Release\QVTKWidgetPlugin.dll to C:\Qt\Tools\QtCreator\bin\plugins\designer and when I start QTCreator, the QVTKWidget shows up on the bottom under the QVTK section of the available form controls.
I add the QVTKWidget to my form and build the application using msvc2013 Release. Then I get the linker errors. What lib am I missing?
Below is my .pro file
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = MIViewer
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
win32 {
INCLUDEPATH += D:\VTK\VTK-7.0.0\GUISupport\Qt
INCLUDEPATH += D:\VTK\VTK-7.0.0\Common\Core
INCLUDEPATH += D:\VTK\VTK-7.0.0\Rendering\Core
}
win32-msvc2013 {
INCLUDEPATH += D:\VTK\vtk32\GUISupport\Qt
INCLUDEPATH += D:\VTK\vtk32\Interaction\Style
INCLUDEPATH += D:\VTK\vtk32\Rendering\Core
INCLUDEPATH += D:\VTK\vtk32\Rendering\OpenGL2
INCLUDEPATH += D:\VTK\vtk32\Common\Core
LIBS += -LD:\VTK\vtk32\lib\Release
}
win32-msvc2013_64 {
INCLUDEPATH += D:\VTK\vtk64\GUISupport\Qt
INCLUDEPATH += D:\VTK\vtk64\Interaction\Style
INCLUDEPATH += D:\VTK\vtk64\Rendering\Core
INCLUDEPATH += D:\VTK\vtk64\Rendering\OpenGL2
INCLUDEPATH += D:\VTK\vtk64\Common\Core
LIBS += -LD:\VTK\vtk64\lib\Release
}
LIBS += -lQVTKWidgetPlugin \
-lvtkGUISupportQt-7.0 \
-lvtkRenderingQt-7.0
Just wanted to answer my own question in case anyone else comes across this post with a similar program. I was able fix this by re-compiling the 32-bit VTK with all of the Cmake Qt options selected and paths filled out. I didn't have the correct paths in CMake, but cmake didn't complain and generated the VS solution files. And I didn't notice that 20% of the projects had failed until I tried to re-compile VTK.
When trying to diagnose linker errors, it's nothing mysterious. There's something missing! Just going through the checklist of dependencies one by one solved it for me.
Related
Seeking for help with linking intel TBB and Qt compiling with MSVC. I don't have any problems when using Visual Studio and linking there, but Qt redflags errors in profiling file as follows:
C:\Program Files (x86)\Intel\oneAPI\tbb\2021.1.1\include\oneapi\tbb\profiling.h(229): error C2059: syntax error: ')'
C:\Program Files (x86)\Intel\oneAPI\tbb\2021.1.1\include\oneapi\tbb\profiling.h(229): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
C:\Program Files (x86)\Intel\oneAPI\tbb\2021.1.1\include\oneapi\tbb\profiling.h(231): error C2059: syntax error: 'const'
C:\Program Files (x86)\Intel\oneAPI\tbb\2021.1.1\include\oneapi\tbb\profiling.h(231): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
My guess it's just qmake options problem, I've searched everywhere to find proper instructions how to link with Qt and couldn't find any.
My .pro file:
QT -= gui
CONFIG += c++17 console
CONFIG -= app_bundle
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
#TBB
INCLUDEPATH += 'C:\Program Files (x86)\Intel\oneAPI\tbb\2021.1.1\include'
win32:CONFIG(release, debug|release): LIBS += -L'C:/Program Files (x86)/Intel/oneAPI/tbb/2021.1.1/lib/intel64/vc_mt/' -ltbb
else:win32:CONFIG(debug, debug|release): LIBS += -L'C:/Program Files (x86)/Intel/oneAPI/tbb/2021.1.1/lib/intel64/vc_mt/' -ltbb_debug
INCLUDEPATH += 'C:/Program Files (x86)/Intel/oneAPI/tbb/2021.1.1/lib/intel64/vc_mt'
DEPENDPATH += 'C:/Program Files (x86)/Intel/oneAPI/tbb/2021.1.1/lib/intel64/vc_mt'
and main:
#include <QCoreApplication>
#include <oneapi/tbb.h>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
return a.exec();
}
I am building a Qt5 project with OpenCV3.4.5 in windows. The OpenCV is a prebuilt version with opencv_world345.lib and opencv_world345dlib. I create a .pri file for including opencv into the Qt project. Here below is for the opencv .pri file:
INCLUDEPATH += C:/opencv-3.4.5/prebuild/include \
C:/opencv-3.4.5/prebuild/include/opencv \
C:/opencv-3.4.5/prebuild/include/opencv2
Debug: {
LIBS += lc:/opencv-3.4.5/prebuild/x64/vc14/lib/opencv_world345d
}
Release: {
LIBS += lc:/opencv-3.4.5/prebuild/x64/vc14/lib/opencv_world345
}
I also set C:\opencv-3.4.5\prebuild\x64\vc14\bin in the path of systems variables.
Building the project in debug mode gives the error: LINK : fatal error LNK1104: cannot open file 'lc:\opencv-3.4.5\prebuild\x64\vc14\lib\opencv_world345d.obj'.
What causes the error? Do I miss something else in configuring opencv for Qt?
Have you run qmake since making your changes to the .pri file?
Normally I would have asked for clarification in the comments, but I'm new to Stack Overflow and don't have 50 reputation yet.
EDIT:
I found an old project of mine that I have OpenCV3.1.0 properly linked to. Here's what I have in my .pro
LIBS += -L*PATH TO OPEN CV*/OpenCV-3.1.0/lib
INCLUDEPATH += *PATH TO OPEN CV*/OpenCV-3.1.0/include
CONFIG(release, debug|release):{
LIBS += \
-lopencv_world310
}
CONFIG(debug, debug|release):{
LIBS += \
-lopencv_world310d
}
Here below is the modified .pri file that works for me!
INCLUDEPATH += c:/opencv-3.4.5/prebuild/include
CONFIG(release, debug|release):{
LIBS += -L"c:/opencv-3.4.5/prebuild/x64/vc14/lib" -lopencv_world345
}
CONFIG(debug, debug|release):{
LIBS += -L"c:/opencv-3.4.5/prebuild/x64/vc14/lib" -lopencv_world345d
}
The configurations by Debug:{} and Release {} do not work!
I am compiling my code with caffe, opencv 3.1 and Qt5.6. Following is my .pro file. I have not included the actual source and header file names here.
QT += core gui network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = outsideSituationDetection
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
<and others>
HEADERS += mainwindow.h \
< and others >
FORMS += mainwindow.ui
DEFINES += CPU_ONLY
QMAKE_CXXFLAGS += -std=c++11 -Wall -D_REENTRANT -D__STDC_CONSTANT_MACROS -pthread
QMAKE_CXXFLAGS += -DQT_COMPILING_QSTRING_COMPAT_CPP -DQT_COMPILING_QIMAGE_COMPAT_CPP
CONFIG += link_pkgconfig
PKGCONFIG += opencv
INCLUDEPATH += /usr/local/include /usr/local/lib /usr/lib
DEPENDPATH += /usr/local/include
LIBS += -L/usr/local/lib/ -lopencv_imgproc
LIBS += -lm -lglib-2.0 -lgthread-2.0 -lxml2 -pthread
INCLUDEPATH += /usr/include/glib-2.0
INCLUDEPATH += /usr/lib/x86_64-linux-gnu/glib-2.0/include
INCLUDEPATH += /usr/include/libxml2
INCLUDEPATH += /usr/include/ \
/usr/lib/x86_64-linux-gnu/ \
LIBS += -L/usr/lib/x86_64-linux-gnu/ -lglog -lpthread -lm -lrt -ldl -lnsl
DEPENDPATH += /usr/lib/x86_64-linux-gnu/
# BOOST Library
LIBS += -L/usr/lib/x86_64-linux-gnu/ -lboost_system
INCLUDEPATH += /usr/lib/x86_64-linux-gnu
#Caffe for CPU System
INCLUDEPATH += $$PWD/../../../../../src/caffe/build/include \
$$PWD/../../../../../src/caffe/include \
$$PWD/../../../../../src/caffe/build
unix:!macx: LIBS += -L$$PWD/../../../../../src/caffe/build/lib/ -lcaffe -lglog
INCLUDEPATH += $$PWD/../../../../../src/caffe/build
DEPENDPATH += $$PWD/../../../../../src/caffe/build
RESOURCES += icons.qrc
Problem - When I compile the code, I get a bunch of 'error: undefined reference to 'QDebug::~QDebug()'' errors along with 'error: undefined reference to `QDebug::putString(QChar const*, unsigned long)'' against all of my .cpp files. (I have successfully built and executed another application without errors using Qt5.6 and Qt5.7.)
(.qtversion[qt_version_tag]+0x0):-1: error: undefined reference to `qt_version_tag' File not found (.qtversion[qt_version_tag]+0x0) in main.o
What I have tried - Check Qt version to make sure I am using Qt5.6. Deleted the installed qt5-default by doing 'sudo apt-get remove qt5-default'. Downgraded from Qt5.7 to Qt5.6 although it didn't make any difference. I have deleted qt4 and qt5 folders from /usr/include and /usr/share.
Can you please suggest what I might be missing?
I had multiple declarations of ' #include "QDebug" ' in files. Removing them and having it in only one file removed the error. (edit- it's incorrect and doesn't work)
What worked - Though I had removed older versions of Qt 3, 4 & 5 , qt was internally using 5.2.1 versions. I do not know where they came from. But when I deleted them all in /usr/lib/x86_linux_gnu/, the code compiled! I also specified the paths to the installed directory explicitly in qtchooser/default.conf. This may not be the best way to do but it worked anyway.
I cannot understand why this Qt pro file does not work:
QT += core
QT += gui
TARGET = PrjName
CONFIG += qt
CONFIG += console
TEMPLATE = app
INCLUDEPATH += C:/Qt/4.8.4/include/Qt
QMAKE_LIBDIR += C:/Qt/4.8.4/bin
LIBS += -lQtCore4
LIBS += -lQtGui4
SOURCES += ...
HEADERS += ...
These are the linker errors:
error: cannot find -lQtGui
error: cannot find -lQtCore
The C:\Qt\4.8.4\bin directory exists, and the DLLs are there.
Thank you.
Platform: Windows 7, MinGW, Qt 4.8.4, QtCreator 2.8.0
I have Qt Creator 2.6.1 based on Qt 5.0
I have build cryptlib with visual studio 2010
all cryptlib project is on C:\SDK\cl342
when I have built the project the crypt.h and cl32.lib and cl32.dll are in this folder
C:\SDK\cl342
I am getting linker error on every method that I call from cryptlib such as cryptInit
I have tried adding it from the project menu and add external library it makes many changes to pro file but does not even let me include crypt.h.
mainwindow.obj:-1: error: LNK2019: unresolved external symbol _cryptEnd#0 referenced in function "public: __thiscall MainWindow::MainWindow(class QWidget *)" (??0MainWindow##QAE#PAVQWidget###Z) –
my pro files looks something like this.
**QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = testlistview
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
INCLUDEPATH = C:\SDK\cl342\
DEPENDPATH += C:\SDK\cl342\
LIBS += C:\SDK\cl342\cl32.lib**