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. Linking Error using Cmake file to build Qt project in Visual Studio
Forum Updated to NodeBB v4.3 + New Features

Linking Error using Cmake file to build Qt project in Visual Studio

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 2.3k 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.
  • N Offline
    N Offline
    nanthiran_2005
    wrote on last edited by
    #1

    Hi all,

    I am trying to build a qt project using cmake. As a startinng point, I started off by just writing a simple code in qt creator, which contains main.cpp, mainwindow.cpp & mainwindow.h. Below are my CMakeLists.txt configuration.

    @
    cmake_minimum_required(VERSION 2.8.11)

    project(testproject)

    Find includes in corresponding build directories

    set(CMAKE_INCLUDE_CURRENT_DIR ON)

    Instruct CMake to run moc automatically when needed.

    set(CMAKE_AUTOMOC ON)

    Find the QtWidgets library

    find_package(Qt5Widgets)
    find_package(Qt5Core)

    get_target_property(QtCore_location Qt5::Core LOCATION)

    Tell CMake to create the executable

    add_executable(testproject WIN32 main.cpp mainwindow.cpp)

    Use the Widgets module from Qt 5.

    target_link_libraries(testproject Qt5::Widgets)
    @

    Cmake did successfully generate the build files. However, when I try to build the executable in visual studio, it gives me linking errors. Some of the errors are listed below. I could not post the whole error list as it is too long.

    @>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __cdecl QWidget::show(void)" (_imp?show@QWidget@@QEAAXXZ) referenced in function main
    2>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl QApplication::QApplication(int &,char * *,int)" (_imp??0QApplication@@QEAA@AEAHPEAPEADH@Z) referenced in function main
    2>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl QApplication::~QApplication(void)" (_imp??1QApplication@@UEAA@XZ) referenced in function main
    2>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static int __cdecl QApplication::exec(void)" (_imp?exec@QApplication@@SAHXZ) referenced in function main
    2>mainwindow.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl QMetaObject::Connection::~Connection(void)" (_imp??1Connection@QMetaObject@@QEAA@XZ) referenced in function "public: __cdecl MainWindow::MainWindow(class QWidget *)" (??0MainWindow@@QEAA@PEAVQWidget@@@Z)
    2>mainwindow.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl QString::~QString(void)" (_imp??1QString@@QEAA@XZ) referenced in function "public: __cdecl MainWindow::MainWindow(class QWidget *)" (??0MainWindow@@QEAA@PEAVQWidget@@@Z)
    2>testproject_automoc.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual int __cdecl QMainWindow::qt_metacall(enum QMetaObject::Call,int,void * *)" (_imp?qt_metacall@QMainWindow@@UEAAHW4Call@QMetaObject@@HPEAPEAX@Z) referenced in function "public: virtual int __cdecl MainWindow::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@MainWindow@@UEAAHW4Call@QMetaObject@@HPEAPEAX@Z)
    2>testproject_automoc.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static struct QMetaObject const QMainWindow::staticMetaObject" (_imp?staticMetaObject@QMainWindow@@2UQMetaObject@@B) referenced in function "void __cdecl `dynamic initializer for 'public: static struct QMetaObject const MainWindow::staticMetaObject''(void)" (??__E?staticMetaObject@MainWindow@@2UQMetaObject@@B@@YAXXZ)
    2>MSVCRT.lib(crtexew.obj) : error LNK2019: unresolved external symbol WinMain referenced in function __tmainCRTStartup@

    I am using Qt5.3.1, cmake 3.0.2 and visual studio 2012.
    How can I solve this problem? Any advice/help is really appreciated.
    Thank you in advance.

    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