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] Moc and Q_DECL_EXPORT

[SOLVED] Moc and Q_DECL_EXPORT

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 5.9k 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.
  • J Offline
    J Offline
    jpalbertini
    wrote on last edited by
    #1

    Hello everybody

    I got a problem trying to build a dll with those linker errors :

    moc_BallsEffect.obj:-1: erreur : LNK2001: symbole externe non résolu "public: static struct QMetaObject const XEEL_ColorMixing_Effect::staticMetaObject" (?staticMetaObject@XEEL_ColorMixing_Effect@@2UQMetaObject@@B)

    moc_BallsEffect.obj:-1: erreur : LNK2019: symbole externe non résolu "public: virtual void * __thiscall XEEL_ColorMixing_Effect::qt_metacast(char const *)" (?qt_metacast@XEEL_ColorMixing_Effect@@UAEPAXPBD@Z) référencé dans la fonction "public: virtual void * __thiscall BallsEffect::qt_metacast(char const *)" (?qt_metacast@BallsEffect@@UAEPAXPBD@Z)

    moc_BallsEffect.obj:-1: erreur : LNK2019: symbole externe non résolu "public: virtual int __thiscall XEEL_ColorMixing_Effect::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@XEEL_ColorMixing_Effect@@UAEHW4Call@QMetaObject@@HPAPAX@Z) référencé dans la fonction "public: virtual int __thiscall BallsEffect::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@BallsEffect@@UAEHW4Call@QMetaObject@@HPAPAX@Z)

    I have two projects. The first one is an sdk (.lib and .dll) and exports a series of qt based classes.
    The second is another dll, which exposes a single method and of course use the sdk.

    Basically I got this class in the dll:

    @
    class BallsEffect : public XEEL_ColorMixing_Effect
    {
    Q_OBJECT
    ...
    }
    @

    And this one in the sdk:
    @
    class Q_DECL_EXPORT XEEL_ColorMixing_Effect : public QObject
    {
    Q_OBJECT
    ...
    }
    @

    I tried a lot of things, and I can't make it work so if anyone had already encountered this problem...

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      when you check the Qt code you will see that this is not how it is used in the Qt sources.
      Don't use Q_DECL_IMPORT/Q_DECL_EXPORT directly, since your implementation needs to export it but the code where you are using it needs to IMPORT it. So you telling the compiler to export something which you actually don't have, thus the linker errors.

      Do something similar like in the Qt sources (qglobal.h):
      @
      #if defined(MAKE_DLL)
      #define MY_DLL_EXPORT Q_DECL_EXPORT
      #else
      #define MY_DLL_EXPORT Q_DECL_IMPORT
      #endif
      @

      Then when building the dll you need to define MAKE_DLL with the compiler defines flag.

      And define the class like this instead:

      @
      class MY_DLL_EXPORT XEEL_ColorMixing_Effect : public QObject
      {
      Q_OBJECT
      ...
      }
      @

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jpalbertini
        wrote on last edited by
        #3

        Thanks for the reply,
        I tried that but I got the following error from msvc:

        error C2491: 'BallsEffect::staticMetaObject' : definition of dllimport function not allowed G:\Dev\XEEL\trunk\XEELEffects\BallsEffect\BallsEffect-VS2010\GeneratedFiles\DebugDLL\moc_BallsEffect.cpp 80 BallsEffect

        I forgot to tell that I use Visual Studio 2010 to build my project on win8.1 x64 and Qt 5.2

        1 Reply Last reply
        0
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          something is still wrong in your code (which you have not posted yet) i guess.

          Please clean your project and rebuild it. If the error still occurs note the following:

          It's not allowed that your exported classes have inline implementations.
          Use the same header file in the dll and your application.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • J Offline
            J Offline
            jpalbertini
            wrote on last edited by
            #5

            Oo didn't know about the inline implementations but I don't use them so it's not a problem.

            In one of my sdk headers I put:
            @
            #if defined(XEEL_SDK_MAKE_DLL)
            #define XEEL_SDK_DLL_EXPORT Q_DECL_EXPORT
            #else
            #define XEEL_SDK_DLL_EXPORT Q_DECL_IMPORT
            #endif
            @
            and use this macro in all the classes I must have access to.
            I use exactly the same headers in both dlls, and when I tried to compile the second dll I got a lot of warnings...

            I found my error, the final class, in this case BallEffect must not use the XEEL_SDK_DLL_EXPORT macro and it works fine :)

            thanks for your help ;)

            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