Hossein
Hossein

Reputation: 26004

Getting unresolved external symbol when trying to compile a Qt application

I created a simple GUI application in QtCreator (QT 4.8.2) and added a function to check the network connectivity:

bool MainWindow::CheckNetworkConnectivity()
{
    QList<QNetworkInterface> interface = QNetworkInterface::allInterfaces();
    for(int i = 0; i < interface.count();i++)
    {
        QNetworkInterface inface = interface.at(i);
        if(inface.IsUp && !inface.IsLoopBack)
        {
            ui->lstLog->addItem(inface.name()+QDateTime::currentDateTime().toString("h:m:s ap"));
            ui->chkConStatus->setChecked(true);
        }
        else{
            ui->chkConStatus->setChecked(false);
        }
    }
    return  ui->chkConStatus->checkState();
}

After that any attempts to compile the code generates the following errors:

    15:21:11: Running steps for project MasterVPN...
15:21:11: Configuration unchanged, skipping qmake step.
15:21:11: Starting: "C:\Qt\Designer\bin\jom.exe" 
    C:\Qt\Designer\bin\jom.exe -f Makefile.Debug
    cl -c -nologo -Zm200 -Zc:wchar_t- -Zi -MDd -GR -EHsc -W3 -w34100 -w34189 -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -I"c:\Qt\4.8.2\include\QtCore" -I"c:\Qt\4.8.2\include\QtGui" -I"c:\Qt\4.8.2\include" -I"c:\Qt\4.8.2\include\ActiveQt" -I"debug" -I"." -I"..\MasterVPN" -I"." -I"c:\Qt\4.8.2\mkspecs\win32-msvc2010" -Fodebug\ @C:\Users\Master\AppData\Local\Temp\mainwindow.obj.4156.31.jom
mainwindow.cpp
    link /LIBPATH:"c:\Qt\4.8.2\lib" /NOLOGO /DYNAMICBASE /NXCOMPAT /DEBUG /MANIFEST /MANIFESTFILE:"debug\MasterVPN.intermediate.manifest" /SUBSYSTEM:WINDOWS "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" /OUT:debug\MasterVPN.exe @C:\Users\Master\AppData\Local\Temp\MasterVPN.exe.4156.5422.jom
mainwindow.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QNetworkInterface::~QNetworkInterface(void)" (__imp_??1QNetworkInterface@@QAE@XZ) referenced in function "public: bool __thiscall MainWindow::CheckNetworkConnectivity(void)" (?CheckNetworkConnectivity@MainWindow@@QAE_NXZ)
mainwindow.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class QString __thiscall QNetworkInterface::name(void)const " (__imp_?name@QNetworkInterface@@QBE?AVQString@@XZ) referenced in function "public: bool __thiscall MainWindow::CheckNetworkConnectivity(void)" (?CheckNetworkConnectivity@MainWindow@@QAE_NXZ)
mainwindow.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QNetworkInterface::QNetworkInterface(class QNetworkInterface const &)" (__imp_??0QNetworkInterface@@QAE@ABV0@@Z) referenced in function "public: bool __thiscall MainWindow::CheckNetworkConnectivity(void)" (?CheckNetworkConnectivity@MainWindow@@QAE_NXZ)
mainwindow.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static class QList<class QNetworkInterface> __cdecl QNetworkInterface::allInterfaces(void)" (__imp_?allInterfaces@QNetworkInterface@@SA?AV?$QList@VQNetworkInterface@@@@XZ) referenced in function "public: bool __thiscall MainWindow::CheckNetworkConnectivity(void)" (?CheckNetworkConnectivity@MainWindow@@QAE_NXZ)
debug\MasterVPN.exe : fatal error LNK1120: 4 unresolved externals
jom: C:\Users\Master\Documents\Qt\MasterVPN-build-desktop-Qt_4_8_2__4_8_2__Debug\Makefile.Debug [debug\MasterVPN.exe] Error 1120
jom: C:\Users\Master\Documents\Qt\MasterVPN-build-desktop-Qt_4_8_2__4_8_2__Debug\Makefile [debug] Error 2
15:21:17: The process "C:\Qt\Designer\bin\jom.exe" exited with code 2.
Error while building/deploying project MasterVPN (target: Desktop)
When executing step 'Make'

Can someone please point out what the cause could be?

Upvotes: 2

Views: 4909

Answers (1)

Bart
Bart

Reputation: 20038

The linker is indicating that is can not find the required functionality. This is contained within QtNetwork4.lib (if you're on a Windows platform) or the equivalent library for your platform. So you have to tell the linker that it needs to link against this library. The network module is the required one, so instead of just

QT += core gui

at least make that

QT += core gui network

That should fix the linker errors you see.

Upvotes: 6

Related Questions