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. cmake automoc + dll... error LNK2001: unresolved external symbol "public: static struct QMetaObject

cmake automoc + dll... error LNK2001: unresolved external symbol "public: static struct QMetaObject

Scheduled Pinned Locked Moved Unsolved General and Desktop
cmakemoc
3 Posts 3 Posters 996 Views
  • 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.
  • D Offline
    D Offline
    Dariusz
    wrote on 30 Nov 2021, 21:26 last edited by Dariusz
    #1

    Hey

    So I've recently started to "dll" up my project.
    So far its been... "fun" but I hit a few walls... mainly with Qt mocs as far as I can tell.

    I can see that my main library gets mocs generated. But then when I make my test they error up with the error in the topic.
    As far as I can tell... I need to somehow include these moc files in dirs for my test apps as well?
    I can see them being generated in libraryA_autogen and some subfolders... there is also mocs_compilation.cpp
    My question is... if I want to include my dll app that uses qt in another app. (as this is backend framework) How do I Deal with mocs?
    Do I have to write some kind of post build command that copies all moc files to some location & ship it with my dll/include folder?
    How can I find those moc files when I make them in 1st place ?

    I have a one - make it all - cmake file that makes lib, then makes test projects & link dlls/libs to each test project.

    Im on Windows, qt6+, cmake

    Can any1 hint me up what to do here?

    As far as I can tell if I include mocs_compilation.cpp in my test cpp, the app compiles properly. so that means I have to "auto include it for all" so that I get those mocs from my framework/dll ?
    Any help/hints? I used .lib in past didnt have to do any of it, but dll fails.

    R 1 Reply Last reply 2 Dec 2021, 20:35
    0
    • M Offline
      M Offline
      mchinand
      wrote on 30 Nov 2021, 21:59 last edited by
      #2

      Are you using the Q_DECL_EXPORT/Q_DECL_IMPORT correctly for the classes in your shared library as described in the docs? This is needed for shared libraries in Windows.

      1 Reply Last reply
      2
      • D Dariusz
        30 Nov 2021, 21:26

        Hey

        So I've recently started to "dll" up my project.
        So far its been... "fun" but I hit a few walls... mainly with Qt mocs as far as I can tell.

        I can see that my main library gets mocs generated. But then when I make my test they error up with the error in the topic.
        As far as I can tell... I need to somehow include these moc files in dirs for my test apps as well?
        I can see them being generated in libraryA_autogen and some subfolders... there is also mocs_compilation.cpp
        My question is... if I want to include my dll app that uses qt in another app. (as this is backend framework) How do I Deal with mocs?
        Do I have to write some kind of post build command that copies all moc files to some location & ship it with my dll/include folder?
        How can I find those moc files when I make them in 1st place ?

        I have a one - make it all - cmake file that makes lib, then makes test projects & link dlls/libs to each test project.

        Im on Windows, qt6+, cmake

        Can any1 hint me up what to do here?

        As far as I can tell if I include mocs_compilation.cpp in my test cpp, the app compiles properly. so that means I have to "auto include it for all" so that I get those mocs from my framework/dll ?
        Any help/hints? I used .lib in past didnt have to do any of it, but dll fails.

        R Offline
        R Offline
        raven-worx
        Moderators
        wrote on 2 Dec 2021, 20:35 last edited by raven-worx 12 Feb 2021, 20:38
        #3

        @Dariusz said in cmake automoc + dll... error LNK2001: unresolved external symbol "public: static struct QMetaObject:

        Do I have to write some kind of post build command that copies all moc files to some location & ship it with my dll/include folder?

        no, the moc data is compiled into your binary, like any other class/method etc.

        Since you are using cmake, did you set the AUTOMOC property?!
        https://doc.qt.io/qt-6/cmake-get-started.html

        --- 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
        2

        3/3

        2 Dec 2021, 20:35

        • Login

        • Login or register to search.
        3 out of 3
        • First post
          3/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved