Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved]main.obj LNK2011 error lead to compile failure in a very simple code
Forum Updated to NodeBB v4.3 + New Features

[Solved]main.obj LNK2011 error lead to compile failure in a very simple code

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 3.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    f_sweeks
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Sam
      wrote on last edited by
      #2

      Do the following steps.

      1. Add QT += network in .pro file then save.
      2. Right Click on your project in project tree ->Clean
      3. Right Click on your project in project tree ->Run qmake
      4. Right Click on your project in project tree ->Build
      5. Run.

      Works for me.

      1 Reply Last reply
      0
      • Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • F Offline
          F Offline
          f_sweeks
          wrote on last edited by
          #4

          Works for me.Thanks.
          [quote author="Sam" date="1359280948"]Do the following steps.

          1. Add QT += network in .pro file then save.
          2. Right Click on your project in project tree ->Clean
          3. Right Click on your project in project tree ->Run qmake
          4. Right Click on your project in project tree ->Build
          5. Run.

          Works for me.
          [/quote]

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Sam
            wrote on last edited by
            #5

            You are welcome :)

            Kindly edit your first post and prepend [SOLVED] to the title .

            Happy Coding !!!

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved