[Solved]main.obj LNK2011 error lead to compile failure in a very simple code
-
Hi.I'm new to Qt and I'm using Qt Creator 5.0.0 in Windows 7. I built a simple console project to test and learn to use QtNetwork/QNetworkAccessManager.Here is the code.
main.cpp:
@
#include <QCoreApplication>
#include <QtNetwork/QNetworkAccessManager>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QNetworkAccessManager NAM;
return a.exec();
}
@the .pro file:(It's generated by Qt Creator automatically and I didn't change it)
@
QT += core
QT -= gui
TARGET = XALFtest2
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
@When I try to compile it,it reports errors like this "main.obj:-1: Error:LNK2001: Unresolved external symbol "__declspec(dllimport) public: virtual __thiscall QNetworkAccessManager::~QNetworkAccessManager(void)" (_imp??1QNetworkAccessManager@@UAE@XZ)" and fails to compile.
I've searched about it for a long time on the Internet,I've tried to add "LIB+=Qt5Network.lib" ,and "QT += network" in the .pro file,and it didn't work.
I'll really appreciate it if you give me any suggestions or tell me any documentation about the problem.Many thanks. -
QT += network should be enough, no need for manual lib including
I sometimes get this error when adding Qt modules manually. You need to re-run qmake. Go to Build -> Run qmake and then rebuild your project. Should be ok.
Btw. There is no Qt Creator 5.0.0. Qt Creator is an IDE and you probably have something like v2.6.1. 5.0.0 is the version of Qt library.
-
Works for me.Thanks.
[quote author="Sam" date="1359280948"]Do the following steps.- Add QT += network in .pro file then save.
- Right Click on your project in project tree ->Clean
- Right Click on your project in project tree ->Run qmake
- Right Click on your project in project tree ->Build
- Run.
Works for me.
[/quote]