I am trying to compile this simple qt application with Visual Studio express 2013 for Desktop:
#include <QApplication.h>
#include <QTextEdit.h>
int main(int argv, char **args)
{
QApplication app(argv, args);
QTextEdit textEdit;
textEdit.show();
return app.exec();
}
but when I compile I have this error :
Errore 1 error LNK2019: riferimento al simbolo esterno
"__declspec(dllimport) public: __thiscall
QApplication::QApplication(int &,char * *,int)"
(__imp_??0QApplication##QAE#AAHPAPADH#Z) non risolto nella funzione
_main C:\Users\Enrico\Documents\Visual Studio 2013\Projects\Progetto2\Progetto2\Origine.obj Progetto2
English:
Error 1 error LNK2019: unresolved external symbol
"__declspec(dllimport) public: __thiscall
QApplication::QApplication(int &,char * *,int)"
(__imp_??0QApplication##QAE#AAHPAPADH#Z) referenced in function
_main C:\Users\Enrico\Documents\Visual Studio 2013\Projects\Progetto2\Progetto2\Origine.obj Progetto2
Thanks for everyone who helps me.
The root cause is the Qt libraries like QtCore5.dll are not being linked. You can manually specify them by editing the Linker options to your project, but but the elegant way is to use the Qt Visual Studio Add-in to easily do a number of things such as create new Qt projects with the Qt libraries selected. This will resolve your link error. The add-in also adds debugger visualization for Qt types, ties in Qt Designer, and many other useful things for using Qt for within Visual Studio.
But add-ins are not supported in Visual Studio Express. Instead you must install Visual Studio 2013 Community. VS 2015 Community is now shipping also, but the Qt add-in hasn't been updated to work with it yet.
Related
I am trying to write an application that saves 16 bit tiffs. I use QT Creator and the QT API, but can't use the QT tiff features because of the 16 bit need. My application needs to work in both Windows and Linux.
The Linux version works fine. When I try and link in Visual C++/Win 7, I get the following error messages:
FrameSaveRunnable.obj : error LNK2019: unresolved external symbol __imp_TIFFClose referenced in function "protected: virtual void __cdecl FrameSaveRunnable::run(void)" (?run#FrameSaveRunnable##MEAAXXZ)
FrameSaveRunnable.obj : error LNK2019: unresolved external symbol __imp_TIFFSetField referenced in function "protected: virtual void __cdecl FrameSaveRunnable::run(void)" (?run#FrameSaveRunnable##MEAAXXZ)
FrameSaveRunnable.obj : error LNK2019: unresolved external symbol __imp_TIFFWriteScanline referenced in function "protected: virtual void __cdecl FrameSaveRunnable::run(void)" (?run#FrameSaveRunnable##MEAAXXZ)
FrameSaveRunnable.obj : error LNK2019: unresolved external symbol __imp_TIFFOpen referenced in function "protected: virtual void __cdecl FrameSaveRunnable::run(void)" (?run#FrameSaveRunnable##MEAAXXZ)
debug\avtcam.exe : fatal error LNK1120: 4 unresolved externals
The relevant parts of my .pro file look like this:
INCLUDEPATH += "C:\Program Files (x86)\GnuWin32\include"
LIBS += -L"C:\Program Files (x86)\GnuWin32\lib" -llibtiff
I have googled and searched all over, and it seems that the problem has to do with C/C++ name incompatabilities. There are some suggestions as to how to fix it inside of Visual Studio, but I am working in the QT environment, and dont use VS at all--just the compiler. Is there an answer to this problem?
My environment: QT 5.4.0, Visual Studio 12, win 7 Pro, libtiff binaries downloaded from http://gnuwin32.sourceforge.net/packages/tiff.htm
You need libtiff compiled for MSVC. MSVC is the significant part of your environment, not Qt.
See http://www.remotesensing.org/libtiff/build.html#PC for instructions for building it (though I'm not sure if those are up to date), or there are other answers on stackoverflow on how to do it (eg Installing LibTiff to Visual Studio 2010).
I can't seem to get a very simple program to compile in Visual Studio 2013. My goal is to incorporate UHD into a C++ program (UHD Driver and Libraries for Windows). I downloaded and installed the Windows UHD package.Since the library also depends on Boost, I also downloaded the appropriate Boost library. After that, I wrote a quick test program in Visual Studio 2013:
#include "stdafx.h"
#include <iostream>
#include <uhd\usrp\multi_usrp.hpp>
#include <uhd\types\device_addr.hpp>
using namespace uhd;
int main(void)
{
device_addr_t hint;
device_addrs_t dev_addrs = device::find(hint);
system("pause");
return 0;
}
In case anyone is interested, this program should locate any USRPs attached to a host PC. I defined the appropriate include paths in Visual Studio: . .
To be clear, I included two paths to the header files:
C:\Program Files (x86)\UHD\include and C:\Program Files (x86)\boost_1_55_0
and one path to the library:
C:\Program Files (x86)\UHD\lib
When I wrote the above program, Visual Studio recognized the additional include files, recognized device_addr_t as a typedef, and didn't throw any errors. However, when I built the program, I received these errors:
Error 3 error LNK2019: unresolved external symbol "__declspec(dllimport) public: static class std::vector<class uhd::device_addr_t,class std::allocator<class uhd::device_addr_t> > __cdecl uhd::device::find(class uhd::device_addr_t const &)" (__imp_?find#device#uhd##SA?AV?$vector#Vdevice_addr_t#uhd##V?$allocator#Vdevice_addr_t#uhd###std###std##ABVdevice_addr_t#2##Z) referenced in function _main C:\Users\...\Documents\Visual Studio 2013\Projects\uhd_test\uhd_test\uhd_test.obj uhd_test
Error 2 error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall uhd::device_addr_t::~device_addr_t(void)" (__imp_??1device_addr_t#uhd##QAE#XZ) referenced in function "public: void * __thiscall uhd::device_addr_t::`scalar deleting destructor'(unsigned int)" (??_Gdevice_addr_t#uhd##QAEPAXI#Z) C:\Users\...\Documents\Visual Studio 2013\Projects\uhd_test\uhd_test\uhd_test.obj uhd_test
Error 1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall uhd::device_addr_t::device_addr_t(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??0device_addr_t#uhd##QAE#ABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z) referenced in function _main C:\Users\...\Documents\Visual Studio 2013\Projects\uhd_test\uhd_test\uhd_test.obj uhd_test
Error 4 error LNK1120: 3 unresolved externals C:\Users\...\Documents\Visual Studio 2013\Projects\uhd_test\Debug\uhd_test.exe uhd_test
I've encountered these errors before in other programs, but I was able to resolve them relatively easily; either I would misspell a crucial include, or there would be an issue with a template class. However, in this instance, I can't seem to resolve the issue.
Any constructive input would be appreciated.
NOTE: In addition to defining the library directory path, I've explicitly added the UHD library, and I receive the same errors.
I got your example working. Here's the software versions I used since you didn't mention much in your description:
Microsoft Visual Studio 2013
VC++ Redistributable Package for VS2013 (vcredist_x86)
UHD 003.007.002, VS2013, Win32
Boost 1.56, lib32-msvc-12.0 binary package
Here are the project configuration properties you need to set in your VS2013 applications:
C/C++ -> General -> Additional Include Directories
C:\local\boost_1_56_0
C:\Program Files (x86)\uhd\include
Linker -> General -> Additional Library Directories
C:\local\boost_1_56_0\lib32-msvc-12.0
C:\Program Files (x86)\uhd\lib
Linker -> Input -> Additional Dependencies
uhd.lib
I think the last step is what's tripping you up, good luck!
I followed exactly what David Greene said, and I ended up with the same errors. Eventually I figured out that I had downloaded the 64-bit UHD, but I was using Visual Studio 2013 Express, which was a 32-bit compiler. Downloading the 32-bit version of UHD for Visual Studio 2013 solved the problem. For anyone else having this problem, double check that the compiler matches which version of UHD you install.
My machine in Windows 7 32-bit and my compiler for C++ is Visual Studio 2012 so first I downloaded FLTK from here (http://www.stroustrup.com/Programming/FLTK/) and then I did the works as follows has wanted me:
I. Unzip the downloaded file and open the main folder, fltk-l.l.? In a
Visual C++ folder (e.g., vc2005 or vcnet), open fltk.dsw. If asked about
updating old project files, choose Yes to All.
PS: My compiler is vc2012 instead of vc2005 and there wasn't any file named fltk.dsw in vc2005 or vcnet folders, so I chose the fltk.sln from vcnet and installed it. There were some failing when installing but it finished finally!
From the Build menu, choose Build Solution. This may take a few minutes.
The source code is being compiled into static link libraries so that
you do not have to recompile the FLTK source code any time you make
a new project. When the process has finished , close Visual Studio.
From the main FLTK directory open the lib folder. Copy (not just
move/drag) all the .lib files except README.lib (there should be
scven) into C:\Prograrn Files\Microsoft Visual Studio\Vc\lib.
Go back to the FLTK main directory and copy the FL folder into
C:\Program Files\Microsoft Visual Studio\Vc\include.
Create a new project in Visual Studio with one change to the usual procedure:
create a "\Vin32 project" instead of a "console application" when
choosing your project type. Be sure to create an "empty project"; otherwise,
some "software wizard" will add a lot of stuff to your project that
you are unlikely to need or understand.
In Visual Studio, choose Project from the main (top) menu, and from
the drop-down menu choose Properties.
In the Properties dialog box, in the left menu, click the Linker folder.
This expands a sub-menu. In this sub-menu, click Input. In the Additional
Dependencies text field on the right, enter the following text:
fltkd.lib wsock32.lib comctl32.lib fltkjpegd.lib fltkimagesd.lib
[The following step may be lIImecessary because il is now the default.]
In the Ignore Specific Library text field, enter the following text:
libcd.lib
[This step may be unnecessary because /MDd is now the default.] In the
left menu of the same Properties window, dick C/C++ to expand a different
sub-menu. Click the Code Generation sub-menu item. In the right
menu, change the Runtime Library drop-down to Multi-threaded
Debug DLL (/MDd). Click OK to close the Properties window.
I this step I added a new item to that newly created project (I named that project testv.cpp) and pasted this simple code for testing the FLTK:
#include <FL/Fl.h>
#include <FL/Fl_box.h>
#include <FL/Fl_Window.h>
//***************************
int main()
{
FI_Window window(200, 200, "Window title");
FL_Box box(O,O,200,200, "Hey, I mean, He llo, World! ");
window.show();
return Fl::run();
}
After running this project (pressing F5), 11 errors appeared! They are in bellow:
Error 1 error LNK2019: unresolved external symbol "public: static int
__cdecl Fl::run(void)" (?run#Fl##SAHXZ) referenced in function _main C:\Users\CS\documents\visual studio 2012\Projects\testv\testv\testv.obj
Error 2 error LNK2019: unresolved external symbol "protected:
__thiscall Fl_Widget::Fl_Widget(int,int,int,int,char const *)" (??0Fl_Widget##IAE#HHHHPBD#Z) referenced in function "public:
__thiscall Fl_Box::Fl_Box(int,int,int,int,char const *)" (??0Fl_Box##QAE#HHHHPBD#Z) C:\Users\CS\documents\visual studio
2012\Projects\testv\testv\testv.obj
Error 3 error LNK2019: unresolved external symbol "public: virtual
__thiscall Fl_Widget::~Fl_Widget(void)" (??1Fl_Widget##UAE#XZ) referenced in function "public: virtual __thiscall
Fl_Box::~Fl_Box(void)"
(??1Fl_Box##UAE#XZ) C:\Users\CS\documents\visual studio
2012\Projects\testv\testv\testv.obj
Error 4 error LNK2001: unresolved external symbol "public: virtual
void __thiscall Fl_Widget::resize(int,int,int,int)"
(?resize#Fl_Widget##UAEXHHHH#Z) C:\Users\CS\documents\visual studio
2012\Projects\testv\testv\testv.obj
Error 5 error LNK2001: unresolved external symbol "protected: virtual
void __thiscall Fl_Box::draw(void)"
(?draw#Fl_Box##MAEXXZ) C:\Users\CS\documents\visual studio
2012\Projects\testv\testv\testv.obj
Error 6 error LNK2001: unresolved external symbol "public: virtual int
__thiscall Fl_Box::handle(int)" (?handle#Fl_Box##UAEHH#Z) C:\Users\CS\documents\visual studio
2012\Projects\testv\testv\testv.obj
Error 7 error LNK2019: unresolved external symbol "public: __thiscall
Fl_Window::Fl_Window(int,int,char const *)"
(??0Fl_Window##QAE#HHPBD#Z) referenced in function
_main C:\Users\CS\documents\visual studio 2012\Projects\testv\testv\testv.obj
Error 8 error LNK2019: unresolved external symbol "public: virtual
__thiscall Fl_Window::~Fl_Window(void)" (??1Fl_Window##UAE#XZ) referenced in function _main C:\Users\CS\documents\visual studio
2012\Projects\testv\testv\testv.obj
Error 9 error LNK2019: unresolved external symbol "public: virtual
void __thiscall Fl_Window::show(void)" (?show#Fl_Window##UAEXXZ)
referenced in function _main C:\Users\CS\documents\visual studio
2012\Projects\testv\testv\testv.obj
Error 10 error LNK2019: unresolved external symbol WinMain#16
referenced in function __tmainCRTStartup C:\Users\CS\documents\visual
studio 2012\Projects\testv\testv\MSVCRTD.lib(crtexew.obj)
Error 11 error LNK1120: 10 unresolved
externals C:\Users\CS\documents\visual studio
2012\Projects\testv\Debug\testv.exe
I think the problem is to do with the creating the project. After I created an empty project from Win32 Project I clicked on Add new item and chose the .cpp type. I don't know was it correct or not.
Any idea for fixing the problem?
You are getting that error because you are entering all the library names on one line without a separator. It is taking the whole list as one library. Click on the ellipsis then enter each library name separated by a newline.
Instead of wsock32.lib, use ws2_32.lib
You are getting that error because you are entering all the library
names on one line without a separator. It is taking the whole list as
one library. Click on the ellipsis then enter each library name
separated by a newline.
Instead of wsock32.lib, use ws2_32.lib
Just to add. To Separate each library, put a semicolon after each library name (ex. libraryname.lib; libraryname.lib) or just press enter on the text box to go to the next line so Visual Studio will read it as next line and anything you enter to it will consider it as a library name.
Example:
libraryname.lib - Now, press enter so it will go to the next line, VS will recognize at a library name.
libraryname.lib - This is the next line and your new library
I am studying C++ and using Microsoft Visual Studio 2015 ^_^
I have a c++ qt5 project under Microsoft visual studio professionnal 2010. I have to include a library .lib in my project that is compiled with Microsoft Visual 2005 and depends of the visual 2005 vorsion of the STL. As a consequence when I try to compile my project I got the following link error (here are the three first errors among more):
libmegamatching.lib(BImage.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: int __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::sputn(char const *,int)" (__imp_?sputn#?$basic_streambuf#DU?$char_traits#D#std###std##QAEHPBDH#Z)
libmegamatching.lib(makeCanonicalImage.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: int __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::sputn(char const *,int)" (__imp_?sputn#?$basic_streambuf#DU?$char_traits#D#std###std##QAEHPBDH#Z)
M_Control.lib(Logger.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: int __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::sputn(char const *,int)" (__imp_?sputn#?$basic_streambuf#DU?$char_traits#D#std###std##QAEHPBDH#Z)
My collegue solved this problem encapsulating the library into a microsoft managed C++ library…but I didn't try that yet because I am not excited about adding a .NET dependencie to my project.
Is there other solutions? Of cours I cannot recompile the library with visual 2010 nor change my visual version.
I was thinking about making a visual 2005 std library .lib…but I don't know if there is a way to do that?
Thanks in advance
You either need to [a] recompile the library using Visual C++ 2010 or [b] encapsulate the library within its own module (DLL) and provide a flat C interface over it.
Within a single module, you cannot mix objects built with different major versions of the Visual C++ libraries.
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 ...