Problems porting Qt 4.7 Project to 5.0 PRO Files and LIB



  • Hi,

    last Weekend I started porting my Qt 4 project to version 5.0. Besides a lot of obsolet functions that I had to replace I've got another big problem.

    While compiling I'm getting Link jom errors. For Example:

    XMLBuch.obj:-1: Fehler:LNK2001: Nicht aufgelöstes externes Symbol ""public: static struct QMetaObject const Medium::staticMetaObject" (?staticMetaObject@Medium@@2UQMetaObject@@B)".

    Till this day I used mingw, I installed VS2010 express with SP1 and the new QT SDK.
    Do I have to change more then the "LIB"-Statement in the Amazon.Pro File?

    Hope some can help me :-)

    Happy New Year to everyone,

    Grisu

    This is my Main PRO File:
    @
    TEMPLATE=subdirs

    CONFIG += ordered
    SUBDIRS += DataObjects
    SUBDIRS += Amazon
    SUBDIRS += SQL
    SUBDIRS += Userinterfaces
    SUBDIRS += Main

    DESTDIR = ./release@

    This is the DataObjects PRO File:

    @TEMPLATE = lib
    CONFIG += dll
    qt
    QT += core
    sql
    widgets
    HEADERS += Ausleihe.h
    Buch.h
    ...
    SOURCES += Ausleihe.cpp
    Buch.cpp
    ...
    DEFINES += BUILD_DLL
    DESTDIR = ../Release
    @

    This is Amazon PRO File
    @
    TEMPLATE = lib
    CONFIG += dll
    qt
    QT += core
    widgets
    network
    xml
    gui
    sql
    HEADERS += XMLBuch.h
    HttpData.h
    bookquerry.h
    sha2.h
    hmac_sha2.h
    XMLCD.h
    xmldvd.h
    SOURCES += XMLBuch.cpp
    HttpData.cpp
    bookquerry.cpp
    XMLCD.cpp
    sha2.c
    hmac_sha2.c
    xmldvd.cpp
    FORMS += ui/bookquerry.ui
    DEFINES += BUILD_DLL
    DESTDIR = ../Release

    Old 4.7: LIBS += "../Release/libDataObjects.a"

    LIBS += "../Release/DataObjects.lib"
    UI_DIR = ../../MediaMaster/Amazon/ui
    @

    This is a sniped from Medium.h File which is Part of DataObjects:

    @#ifndef MEDIUM_H_
    #define MEDIUM_H_

    #ifdef BUILD_DLL
    #define EXPORT_DLL Q_DECL_EXPORT
    #else
    #define EXPORT_DLL
    #endif

    #include "Objektverwalter.h"
    #include "../SQL/SQLBase.h"
    #include "SpracheListe.h"

    #include <QDate>

    class EXPORT_DLL Medium: public QObject,
    public Objektverwalter,
    public SQLBase
    {
    Q_OBJECT
    public:
    Medium(QObject *parent =0);
    virtual ~Medium();@



  • At a guess you have a missing Q_OBJECT macro or have not re-run qmake since adding it. The missing object is generated by moc.

    If you use this form of the LIBS variable you allow Qt and your linker to worry about "correct" library naming.

    @
    LIBS += -L../Release -lDataObjects
    @



  • i've also downloaded Qt5-VisualStudio2010 and facing the same problem when porting Qt4 to Qt5: http://qt-project.org/forums/viewthread/23253/

    everything is 'unresolved external symbol', how strange!



  • Both tips don't work :-(.
    I don't think that a QObject is missing because it works fine in Qt4.

    I will build a sample project and try it with that one.

    By the way these are the Qmake settings:
    qmake.exe C:\Temp\MediaMaster\MediaMaster.pro -r -spec win32-msvc2010 "CONFIG+=debug" "CONFIG+=declarative_debug" "CONFIG+=qml_debug"



  • Hi
    I just build an micro project:
    http://dl.dropbox.com/u/16466900/Test.zip
    two Pro Files in each case one Class.

    And still the same problem:
    XMLBuch.obj : error LNK2001: Nicht aufgelöstes externes Symbol ""public: static struct QMetaObject const Medium::staticMetaObject" (?staticMetaObject@Medium@@2UQMetaObject@@B)".

    I think its a Qreator or VS settings Problem

    Test.pro:
    @
    TEMPLATE=subdirs

    CONFIG += ordered
    SUBDIRS += DataObjects
    SUBDIRS += Amazon
    DESTDIR = ./release
    @

    DataObjects.pro
    @
    TEMPLATE = lib
    CONFIG += dll
    qt
    QT += core
    sql
    widgets
    HEADERS += Medium.h
    SOURCES += Medium.cpp
    DEFINES += BUILD_DLL
    DESTDIR = ../Release
    @

    Medium.h
    @#ifndef MEDIUM_H_
    #define MEDIUM_H_

    #ifdef BUILD_DLL
    #define EXPORT_DLL Q_DECL_EXPORT
    #else
    #define EXPORT_DLL
    #endif
    #include <QObject>

    class EXPORT_DLL Medium: public QObject
    {
    Q_OBJECT
    public:
    Medium(QObject *parent =0);
    virtual ~Medium();

    void setURL(QString strURL);
    QString getURL();
    private:
    QString m_strURL;
    };

    #endif /MEDIUM_H_/
    @

    Medium.cpp
    @#include "Medium.h"
    #include <QObject>
    #include <QString>

    Medium::Medium(QObject *parent):QObject(parent){
    }

    Medium::~Medium(){
    }

    void Medium::setURL(QString strURL){
    m_strURL = strURL;
    }
    QString Medium::getURL(){
    return m_strURL;
    }@

    Amazon.pro
    @TEMPLATE = lib
    CONFIG += dll
    qt
    QT += core
    widgets
    network
    xml
    gui
    sql
    HEADERS += XMLBuch.h
    SOURCES += XMLBuch.cpp
    DEFINES += BUILD_DLL
    DESTDIR = ../Release
    LIBS += -L../Release -lDataObjects
    @

    XMLBuch.h
    @#ifndef XMLBUCH_H_
    #define XMLBUCH_H_

    #ifdef BUILD_DLL
    #define EXPORT_DLL Q_DECL_EXPORT
    #else
    #define EXPORT_DLL
    #endif

    #include <QByteArray>

    class EXPORT_DLL XMLBuch
    {
    public:
    XMLBuch(QByteArray xmlText);
    virtual ~XMLBuch();
    };

    #endif /XMLBUCH_H_/
    @

    XMLBuch.cpp
    @#include "XMLBuch.h"

    #include "../DataObjects/Medium.h"
    XMLBuch::XMLBuch(QByteArray xmlText){
    Medium med;
    med.setURL("Dummy");
    }

    XMLBuch::~XMLBuch(){
    }

    @



  • Your test project builds just fine on my Linux box with Qt 4.8.4. In a MSVC/Qt command prompt try the basic clean build:
    @
    qmake
    nmake
    @

    If that works (I expect it will) then the problem is in what your VS project is running to build your project. Make sure that moc is being run by VS.



  • Hi,
    I'm using Qt Creator 2.6.1.
    I never comiled my Project with command prompt.
    I'll try it when I'm at home.

    Grisu



  • Hi,

    I started "Qt 5.0.0 for Desktop (MSVC 2010)" Command prompt.
    With these commands:
    "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86
    qmake
    nmake

    And still an error:
    "c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\nmake.exe" -
    f Makefile.Release

    Microsoft (R) Program Maintenance Utility, Version 10.00.30319.01
    Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten.

        cl -c -nologo -Zm200 -Zc:wchar_t -O2 -MD -GR -W3 -w34100 -w34189 -EHsc -
    

    DUNICODE -DWIN32 -DBUILD_DLL -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_OPENG
    L_ES_2 -DQT_OPENGL_ES_2_ANGLE -I"......\Qt\Qt5.0.0\5.0.0\msvc2010\include" -I"
    ......\Qt\Qt5.0.0\5.0.0\msvc2010\include\QtGui" -I"......\Qt\Qt5.0.0\5.0.0\m
    svc2010\include\QtCore" -I"release" -I"......\Qt\Qt5.0.0\5.0.0\msvc2010\mkspec
    s\win32-msvc2010" -Forelease\ @C:\Users\Grisu\AppData\Local\Temp\nmF3D0.tmp
    XMLBuch.cpp
    link /NOLOGO /DYNAMICBASE /NXCOMPAT /INCREMENTAL:NO /DLL /MANIFEST /MANI
    FESTFILE:..\Release\Amazon.dll.embed.manifest /OUT:..\Release\Amazon.dll @C:\Use
    rs\Grisu\AppData\Local\Temp\nmF5A5.tmp
    Bibliothek "..\Release\Amazon.lib" und Objekt "..\Release\Amazon.exp" werden
    erstellt.
    XMLBuch.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""pub
    lic: static struct QMetaObject const Medium::staticMetaObject" (?staticMetaObjec
    t@Medium@@2UQMetaObject@@B)" in Funktion ""public: static class QString __cdecl
    Medium::tr(char const *,char const *,int)" (?tr@Medium@@SA?AVQString@@PBD0H@Z)".

    ..\Release\Amazon.dll : fatal error LNK1120: 1 nicht aufgelöste externe Verweise
    .
    NMAKE : fatal error U1077: ""c:\Program Files (x86)\Microsoft Visual Studio 10.0
    \VC\BIN\link.EXE"": Rückgabe-Code "0x460"
    Stop.
    NMAKE : fatal error U1077: ""c:\Program Files (x86)\Microsoft Visual Studio 10.0
    \VC\BIN\nmake.exe"": Rückgabe-Code "0x2"
    Stop.
    NMAKE : fatal error U1077: "cd": Rückgabe-Code "0x2"
    Stop.



  • Sorry that I pop-up this topic again.
    Yesterday evening I Installed the XP Mode on my Windows 7 PC.
    Next step was installing MSVS C++ 2010 and then the qt 5.0.0 vs2010 SDK.

    I started the Creator and build the project,..... same Problem

    Do I have to do something else, because ChrisW67 wrote that the Code is correct.

    Hope someone can help me.

    Grisu


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.