Qt move constructor linking error - c++

I'm trying to compile a project in Visual Studio 2010, with Qt 4.8.4.
When I build it, I obtain linker errors like following ones:
error LNK2001: external symbol "__declspec(dllimport) public: class QByteArray & __thiscall QByteArray::operator=(class QByteArray &&)" (__imp_??4QByteArray##QAEAAV0#$$QAV0##Z) not resolved
error LNK2001: external symbol "__declspec(dllimport) public: class QString & __thiscall QSTring::operator=(class QString &&)" (__imp_??QString##QAEAAV0#$$QAV0##Z) not resolved
You can see the move constructor in linker, but I'm not using any C++11 feature.
The linker error appears in files where I've code like this:
QByteArray xTmpArray;
QString xString;
...
xTmpArray = xString.toAscii();
If I comment the assignment line, the link error disappears (same for QString assignment).
How can I eliminate these link errors?

I've solved. It was (naturally) a linking problem, because they gave me libraries compiled with Visual Studio 2008, that does not support move constructor. I've used the correct version, compiled with VS2010, and all works ok.

I wrote this code:
#include <QString>
#include <QByteArray>
int main() {
QString s("a");
QByteArray ba = s.toAscii();
return 0;
}
I am compiling it with command:
g++ -I /usr/include/qt4/QtCore/ -I/usr/include/qt4/ qtuse.cpp -lQtCore -o qtuse
And I have no problem. Looks like you have forgotten to link your program with QtCore.
Check your project settings. You should add Qt's lib dir to link paths.

In Microsoft Visual Studio 2015 go to:
(Project properties)->General->Platform Toolset
and set that to visual studio 2013 (v120)
This have worked for me :)

This error happens when there is version mismatch between MSVC and pre-built Qt binaries. Don't do that.
If you're using MSVC2015 you need to link against the pre-build MSVC2015 Qt libraries.

Related

Linking errors for Qt and cvv when building OpenCV in Windows 10

I am trying to build OpenCV according to these instructions. After generating with CMake I opened OpenCV.sln in the build folder, switched to Release mode and built ALL_BUILD successfully. But when I try to build the INSTALL option under CMake, I get errors like this:
Error LNK2001 unresolved external symbol "public: virtual struct QMetaObject const * __cdecl cvv::qtutil::Signal::metaObject(void)const "
Error LNK2019 unresolved external symbol "public: void __cdecl cvv::qtutil::ZoomableImage::updateConversionResult(class cv::Mat const &,enum cvv::qtutil::ImageConversionResult)const "
...
I am installing OpenCV 4.2 on Windows 10 with Visual Studio 19. How can I solve this problem?
Here is an image of the error messages in Visual Studio:
Turning my comments into an answer:
The GitHub issue described here references similar errors to those you have posted. While the suggested "solution" seems more like a work-around, it may help resolve the issue. First, try building without the cvv module (an interactive GUI component of OpenCV), by running CMake with the BUILD_opencv_cvv variable set to OFF:
cmake -DBUILD_opencv_cvv=OFF ...
You can also set the variable using the CMake GUI, by clicking the Add Entry button, and defining BUILD_opencv_cvv to OFF.
The GitHub issue further explains that if there are still undefined reference errors after making this change, you can also try setting BUILD_opencv_world to OFF as well.
cmake -DBUILD_opencv_cvv=OFF -DBUILD_opencv_world=OFF ...
This may help get things building successfully, but it should be noted that these disabled modules will be left out of your build.

LINK2001 When Building Visual Studio Project, BGSLIbrary, where is Linker in v2017

I am trying to build the BGSLibrary for Windows 10, cmake 3.9, with python support, built with opencv 3.1 and boost 1.64.0 with Visual Studio Community 2017.
Can someone more familiar with Visual Studio interpret this error for me. The c++ seems to compile great, but then project solution fails. It starts by building all the .obj files
2>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.10.25017\bin\HostX86\x86\Lib.exe /OUT:"C:\Users\Ben\Documents\bgslibrary\build\libbgs.lib" /NOLOGO /machine:X86 libbgs.dir\Release\AdaptiveBackgroundLearning.obj
2>libbgs.dir\Release\AdaptiveSelectiveBackgroundLearning.obj
2>libbgs.dir\Release\CodeBook.obj
2>libbgs.dir\Release\DPAdaptiveMedian.obj
2>libbgs.dir\Release\DPEigenbackground.obj
The general error reads.
5>libbgs.lib(LBSP.obj) : error LNK2019: unresolved external symbol "public: virtual void __thiscall cv::Feature2D::read(class cv::FileNode const &)" (?read#Feature2D#cv##UAEXABVFileNode#2##Z) referenced in function "[thunk]:public: virtual void __thiscall cv::Feature2D::read`vtordisp{4294967292,0}' (class cv::FileNode const &)" (?read#Feature2D#cv##$4PPPPPPPM#A#AEXABVFileNode#2##Z)
But the file LBSP.obj compiled fine just 100 lines earlier? I can see it here.
This file was created during the build, why can't it link? Where do I need to add this dir?
I'm reading other SO questions that this error may mean I need to add additional paths, which was done pre-VS2017 by going to PROPERTIES->LINKER->ADDITIONAL DEPENDENCIES. I don't see this option or structure anymore.
3>C:\Users\Ben\Documents\opencv\modules\core\include\opencv2/core/types_c.h(894)
This was a Cmake path error, not a Visual Studio error. Adding OpenCV/bin to path solved this.

Building a minimal Qt Console Project fails with a cryptic Linker Error LNK2001: Unresolved external Symbol

I am trying to compile a minimal Qt Console application with event loop and a custom class with inline definition of its constructor like https://stackoverflow.com/a/4182144/1619432 and get three cryptic linker errors (using Qt 4.8.1 and MSVC 2010 Express C++):
main.obj:-1: error: LNK2001: Unresolved external symbol ""public: virtual struct QMetaObject const * __thiscall ....
with ::metaObject, ::qt_metacast, ::qt_metacall.
#include "main.moc"
just above the int main(...) is critical. If the file is not found, try cleaning the project / deleting the build directories, running qmake, restarting Qt Creator or even the whole system.
This may have to do with paths in environment variables (maybe set previously by a different project).
Another common reason seems to be a forgotten Q_OBJECT macro in the class declaration, or as above, run qmake after including it.
Good luck!

boost LNK2019 error

I read through the boost documentation using the '5.3.4 Invoke b2' and followed up with forum threads that explained details of linking the boost library to the header and linker directories, in the boost help '4.1 Build From the Visual Studio IDE', and found this cool boost related wiki that explained the bjam.exe controls.
placed #include <boost/thread/thread.hpp> in the main.cpp
And, I get this linker error, and the existing help threads have identified the problem is with x64:
Directory path and x32/x64
unrelated to Visual studio
unresolved
The error:
error LNK2019: unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::generic_category(void)" (?generic_category#system#boost##YAAEBVerror_category#12#XZ) referenced in function "void __cdecl boost::system::`dynamic initializer for 'posix_category''(void)" (??__Eposix_category#system#boost##YAXXZ) main.obj
error LNK2019: unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::system_category(void)" (?system_category#system#boost##YAAEBVerror_category#12#XZ) referenced in function "void __cdecl boost::system::`dynamic initializer for 'native_ecat''(void)" (??__Enative_ecat#system#boost##YAXXZ) main.obj
they are similar, something about 'posix_category' and something about 'native_ecat'
So, I tried to build the x64 boost library, and found conflicting instructions on where to put these:
did not say "Note for x64 users: Add the address-model=64 option to bjam (after the threading argument) in order to build static libs with the 64-bit compiler."
cant find the link but one said to place x64 lib in the vs2008 bin?
Also, I tried changing the vs2008 configuration back to x32 -> solutionExplorer/solution_properties/configuration_manager/active_solution_platform - Win32, closed and reopened visual studio - relinked the additional directories C/C++/general and Linker/general to Boost/root and Boost/stage/lib - and it compiled without error.
My best guess at the b2 commands is --toolset=msvc-9.0 address-model=64 --build-type=complete --stagedir=lib\x64 stage
Please give concise instructions for how to build and install x64 version of boost on VS2008. Also, what was the wiki talking about for release and debug - they are not in Boost invocation?
use c++ 11
It more or less includes all the features of boost I wanted to use, also compiles in g++ without figuring out how to build the boost library on my university server and then reference into a remote g++ build - pretty much solved everything with that

Problems with Qt 4.6 in VS 2008

sys info : win xp SP3 , Microsoft Visual Studio 2008
Version 9.0.21022.8 RTM
Microsoft .NET Framework
Version 3.5 SP1
Qt Add-in 1.1.5
I installed Qt 4.6.3 from the site http://qt.nokia.com/downloads/windows-cpp-vs2008.
Then I added the Add-in Qt 1.1.5 and configured the PATH variable.
When I open a new QT project , default example works just fine.
On Nokia (qt) site I found some examples but it seems that things are not working properly.
Here is one of many examples that do not work :
#include <QtGui>
#include <QWidget>
class QLabel;
class QLineEdit;
class QTextEdit;
class AddressBook : public QWidget
{
Q_OBJECT
public:
AddressBook(QWidget *parent = 0);
private:
QLineEdit *nameLine;
QTextEdit *addressText;
};
AddressBook::AddressBook(QWidget *parent)
: QWidget(parent)
{
QLabel *nameLabel = new QLabel(tr("Name:"));
nameLine = new QLineEdit;
QLabel *addressLabel = new QLabel(tr("Address:"));
addressText = new QTextEdit;
QGridLayout *mainLayout = new QGridLayout;
mainLayout->addWidget(nameLabel, 0, 0);
mainLayout->addWidget(nameLine, 0, 1);
mainLayout->addWidget(addressLabel, 1, 0, Qt::AlignTop);
mainLayout->addWidget(addressText, 1, 1);
setLayout(mainLayout);
setWindowTitle(tr("Simple Address Book"));
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
AddressBook addressBook;
addressBook.show();
return app.exec();
}
Compiler says this ::
Output Window
Linking...
main.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall AddressBook::metaObject(void)const " (?metaObject#AddressBook##UBEPBUQMetaObject##XZ)
main.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall AddressBook::qt_metacast(char const *)" (?qt_metacast#AddressBook##UAEPAXPBD#Z)
main.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall AddressBook::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall#AddressBook##UAEHW4Call#QMetaObject##HPAPAX#Z)
main.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const AddressBook::staticMetaObject" (?staticMetaObject#AddressBook##2UQMetaObject##B)
C:\Documents and Settings\nik\My Documents\Visual Studio 2008\Projects\vs_03\Debug\vs_03.exe : fatal error LNK1120: 4 unresolved externals
Results
Build log was saved at "file://c:\Documents and Settings\nik\My Documents\Visual Studio 2008\Projects\vs_03\vs_03\Debug\BuildLog.htm"
vs_03 - 5 error(s), 0 warning(s)
It seems to me that the thing has to do with the use of macro Q_OBJECT but just dont know what to do that thing starts to work properly.
Maybe wrong installation or ... NO IDEA
Any help is appreciated.
I don't think it's a wrong installation - I assume you're using Visual Studio to build the project and in that case, you also need to tell it to build the _moc.cpp files that should have been generated for your class AddressBook.
If they haven't been generated you also need to run moc on the header files for AddressBook.
Any time you need moc to run against your files and you don't have your class in a separate header and implementation file you need to have a #include "FILENAME.moc" at the end of your file. If you were to add that after your main function, everything should work.
You should be able to test this by going into your project directory and doing the following:
Delete any makefiles that may be present
Run the Visual Studio Command Prompt
Run qmake -project to generate a project file
Run qmake to generate the makefiles
Run nmake to build the project
The nmake command should completely successfully and without linking errors on a simple project like the above. For more complex projects, you might need to modify the .pro file to include Qt`s webkit or otherwise make accessible options which are not available by default.
The alternative is to move the class definition for AddressBook into a header file with an appropriate implementation (cpp/cxx) file.
I find solution.
Read all the details about the installation on this page >>
http://dcsoft.wordpress.com/?aspxerrorpath=/community_server/blogs/dcsoft/archive/2009/03/06/how-to-setup-qt-4-5-visual-studio-integration.aspx.
After a whole day of studying and configuration, I finally managed to enable QT 4.6.3. on the VS 2008. Follow the detailed instructions and there should not be a problem.
My problem was that I used the following options:
Starting with Qt 4.6, the LPGL version now comes pre-built for Visual Studio 2008 RTM. If this fits your need, you can simply install it and skip to INSTALL VISUAL STUDIO ADD-IN.
This was wrong in my case so I go to next chapter :
DOWNLOAD QT SOURCE CODE
As the option to download only the Qt source code is a bit obfuscated on the current Nokia website, please follow these directions: ................................................................................................................................................................................................................................. etc. READ ON THE SITE.
For now all works great.There are no errors in linking. MOC works fine ...