Search code examples
c++qtwebkitqt5

Unresolved external symbol. C++


When I try to compile my test app it fails.

CMakeLists.txt:

cmake_minimum_required( VERSION 2.8.8 )
project( webkit-test )

set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

find_package( Qt5Core )
find_package( Qt5Gui )
find_package( Qt5OpenGL )
find_package( Qt5Network )
find_package( Qt5WebKit )
find_package( Qt5Widgets )

add_executable( webkit-test main.cpp )

qt5_use_modules( webkit-test Core Gui OpenGL Network WebKit Widgets )

C++ code:

#include <QtWidgets/QApplication>
#include <QtWebKit/QWebView>

int main( int argc, char *argv[] )
{
        QString file;
        if ( argc >= 2 )
                file = argv[1];

        QApplication a( argc, argv );

        return a.exec();
}

I generate makefile by cmake -G "NMake Makefiles" (3) and then use nmake (4).

After I received that I used dumpbin /EXPORTS QtWebKit5.dll > QtWebKit5.dll.exports.txt and dumpbin /EXPORTS QtWebKit5.lib > QtWebKit5.lib.exports.txt for seeing to exporting symbols: (5) and (6).

By using Ctrl+F you can find in these files "unresolved" external symbols:

?staticMetaObject@QWebPage@@2UQMetaObject@@B (public: static struct QMetaObject const QWebPage::staticMetaObject)

?staticMetaObject@QWebView@@2UQMetaObject@@B (public: static struct QMetaObject const QWebView::staticMetaObject)

If symbols are in QtWebKit5.lib, why I have these errors when linking?


Solution

  • I added add_definitions(-DQT_DLL) to my CMakeLists.txt and now it's compiled.