The meaning of life is to explore the world

Setting up Qt, CMake with Visual Studio

Posted on By Jason Liu

https://blog.csdn.net/Bruce_0712/article/details/53574170

Some errors that may occur:

  1. VS Compiling Error

    Microsoft Visual Studio

    Unable to start program ‘D:\jobs\8i\CodingTest\ForegroundExtractionApp\out\build\x64\Debug\ALL_BUILD’.

    Access is denied.

    Solution:
    Don’t set ALL_BUILD as startup project

  2. VS Linking Error

    ForegroundExtractionApp.exe - 系统错误

    由于找不到 VCRUNTIME140D_APP.dll,无法继续执行代码。重新安装程序可能会解决此问题。

    Solution:
    Copy DLLs from msvc2017_64\bin instead of winrt_x64_msvc2017\bin

  3. CMake Error

    qt_wrap_ui called with incorrect number of arguments

    Solution:
    Use qt5_wrap_ui instead

  4. Runtime Error (debug)

    Cannot find Qt5Cored.dll

    Solution:
    Find them and copy to build\MyCMakeLearner\Debug

  5. Linking Error

    Error LNK2001 unresolved external symbol “public: virtual struct QMetaObject const * __cdecl MyImageLabel::metaObject(void)const “ (?metaObject@MyImageLabel@@UEBAPEBUQMetaObject@@XZ) ForegroundExtractionApp D:\jobs\8i\CodingTest\ForegroundExtractionApp\out\build\ForegroundExtractionApp\mainwindow.obj 1

    Solution:
    Include .h into qt5_wrap_cpp (source_moc ${headers})