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. Mac, Static lib, Dynamic lib Lost signals!
QtWS25 Last Chance

Mac, Static lib, Dynamic lib Lost signals!

Scheduled Pinned Locked Moved Unsolved General and Desktop
staticstaticlibrarydynamicdynamiclibrarymac
13 Posts 2 Posters 1.5k 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 6 Jan 2022, 09:57 last edited by
    #1

    Hey

    So this is a fun one. I'm cross-compiling from Windows to Mac.

    I have a

    1. Static Lib framework
    2. Static lib app
    3. Dynamic lib plugin.
    4. App - he includes 1. & 2. static & dynamically import after startup 3. dyn lib plugin.

    When the plugin runs & creates objects from either static lib 1. or 2. The Signal connections do not work. I get a warning that the object does not have a signal...

    I do not do any export __declexport etc thini, since they are static libraries and I never had to do it for windows before... but maybe I have to do it for... mac?

    Any hints?

    Regards
    Dariusz

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 6 Jan 2022, 14:40 last edited by
      #2

      Hi,

      Do you mean that you have plugins that link to the same static library as your application ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • D Offline
        D Offline
        Dariusz
        wrote on 9 Jan 2022, 18:23 last edited by
        #3

        @SGaist said in Mac, Static lib, Dynamic lib Lost signals!:

        Hi,

        Do you mean that you have plugins that link to the same static library as your application ?

        Eeee... yes. It links to both of these libs, the 1. and 2. When it creates any of objects from these libs, the signals do not connect.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 9 Jan 2022, 19:33 last edited by
          #4

          Try again using a dynamic common library.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          D 1 Reply Last reply 26 Jan 2022, 01:16
          0
          • S SGaist
            9 Jan 2022, 19:33

            Try again using a dynamic common library.

            D Offline
            D Offline
            Dariusz
            wrote on 26 Jan 2022, 01:16 last edited by
            #5

            Hey !

            @SGaist I think I finally found the issue! It seems to be to do with https://forum.qt.io/topic/102783/qobject-connect-signal-not-found-in-dll-with-pointer-to-member-function/3 and mainly > See the Creating Shared Libraries chapter in Qt's documentation.

            I'm gonna dig in and see how I could fix that.

            I just wonder how, I have a cmake project which esentially

            createLibrary()
            createTestExe()
            linkLibraryToTestExe()
            

            And if I understand the post & docs... I have to do something like this

            setFlagExport()
            createLibrary()
            setFlagImport()
            createTestExe()
            linkLibraryToTestExe()
            

            But I never did that, so I wonder. Gonna test it out soon!

            When it comes to annotating those export/import... do I only annotate class or also function/signal/slot?

            TIA

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 26 Jan 2022, 21:57 last edited by
              #6

              Annotate what you want to export. Usually the whole classe.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              D 1 Reply Last reply 27 Jan 2022, 21:32
              0
              • S SGaist
                26 Jan 2022, 21:57

                Annotate what you want to export. Usually the whole classe.

                D Offline
                D Offline
                Dariusz
                wrote on 27 Jan 2022, 21:32 last edited by Dariusz
                #7

                @SGaist said in Mac, Static lib, Dynamic lib Lost signals!:

                Annotate what you want to export. Usually the whole classe.

                Thanks!

                I'm also failing with it... In my head I Have to define a variable in cmake, that then I read in .h and configure macro properly for export/import, but when I run this >

                    add_definitions(-D_BUILD_TYPE=\"library\")
                    add_library(${exename} "${_libraryMode}" "${_librarySource}")
                    add_definitions(-D_BUILD_TYPE=\"app\")
                

                When I run test app, the macro value is library, where as it should be app I think... ?
                How do I eee... make it tick ?
                Or am I looking at it wrong?

                I have 1 project that creates library & includes it in test exe app for testing, I take test exe app should have DLLIMPORT where as library needs DLLEXPORT... How do I bit this thing? o.o

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 27 Jan 2022, 21:36 last edited by
                  #8

                  Did you already read the dedicated chapter in Qt's documentation ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    Dariusz
                    wrote on 27 Jan 2022, 21:59 last edited by
                    #9

                    Yeah thats what I'm trying to follow. But I'm using CMake not qmake. I also don't know how to "undefined" it
                    DEFINES += MYSHAREDLIB_LIBRARY it in CMake, I tried remove_definitions() but that did not work.

                    I also wonder if I have to do it on mac? Windows works fine, its mac that is broken.

                    Say my cmake is something like:

                    add_definitions(-D_BUILD_TYPE=\"library\")
                    add_library(libraryTest SHARED libA.cpp libA.h)
                    remove_definitions(-D_BUILD_TYPE)
                    add_executable(testLib test_main.cpp)
                    target_link_libraries(testLib libraryTest)
                    

                    When I do

                    int main(){
                    auto val = _BUILD_TYPE;
                    std::cout<<val<<std::endl;
                    return 1;
                    }
                    

                    In my testLib, it still prints library. Or is this some kind of false positive? I'm trying to wrap my head around it all.

                    D 1 Reply Last reply 27 Jan 2022, 22:04
                    0
                    • D Dariusz
                      27 Jan 2022, 21:59

                      Yeah thats what I'm trying to follow. But I'm using CMake not qmake. I also don't know how to "undefined" it
                      DEFINES += MYSHAREDLIB_LIBRARY it in CMake, I tried remove_definitions() but that did not work.

                      I also wonder if I have to do it on mac? Windows works fine, its mac that is broken.

                      Say my cmake is something like:

                      add_definitions(-D_BUILD_TYPE=\"library\")
                      add_library(libraryTest SHARED libA.cpp libA.h)
                      remove_definitions(-D_BUILD_TYPE)
                      add_executable(testLib test_main.cpp)
                      target_link_libraries(testLib libraryTest)
                      

                      When I do

                      int main(){
                      auto val = _BUILD_TYPE;
                      std::cout<<val<<std::endl;
                      return 1;
                      }
                      

                      In my testLib, it still prints library. Or is this some kind of false positive? I'm trying to wrap my head around it all.

                      D Offline
                      D Offline
                      Dariusz
                      wrote on 27 Jan 2022, 22:04 last edited by
                      #10

                      Uuu I might be able to do it using

                      https://cmake.org/cmake/help/latest/command/target_compile_definitions.html

                      target_compile_definitions(${exename} PRIVATE  DBUILD_TYPE=\"library\")
                      
                      D 1 Reply Last reply 27 Jan 2022, 22:37
                      0
                      • D Dariusz
                        27 Jan 2022, 22:04

                        Uuu I might be able to do it using

                        https://cmake.org/cmake/help/latest/command/target_compile_definitions.html

                        target_compile_definitions(${exename} PRIVATE  DBUILD_TYPE=\"library\")
                        
                        D Offline
                        D Offline
                        Dariusz
                        wrote on 27 Jan 2022, 22:37 last edited by Dariusz
                        #11

                        Hey
                        @SGaist sadly no luck.
                        I added target_compile_definitions private/public. & added macro to the 2 classes that I try to signal/slot link. Rebuild all, hes still failing to find the files. Here is structure of the app

                        libraryA = static
                        libraryB = static
                        pluginA = SHARED
                        exeA = link libraryA & libraryB 
                        exeA.runtime. include plugins from folders, pluginA. 
                        pluginA creates object from libraryB = QObject::connect: signal not found in ...
                        

                        I'm loss. Windows works just fine, Mac M1 ARM has a bad time. Should I somehow... configure something for it to work on ARM ?

                        Im making my signals slots like this :

                            Q_SIGNALS:
                                void sHandleAddGroup();
                                void sHandleAddCommit();
                            public Q_SLOTS:
                                void handleAddCommit();
                        

                        Is any of it due to ARM arch ? o.o

                        1 Reply Last reply
                        0
                        • D Offline
                          D Offline
                          Dariusz
                          wrote on 27 Jan 2022, 23:16 last edited by
                          #12

                          Ok so I found a work around. Its nasty...

                                  //connect(mMainWidgetPtr, &icVCManagerGUI::sHandleAddCommit, this, &icVCManager::handleAddCommit);
                          

                          To

                                  connect(mMainWidgetPtr, SIGNAL(sHandleAddCommit()), this, SLOT(handleAddCommit()));
                          

                          Same errors as bois here>
                          https://forum.qt.io/topic/75801/signal-not-found-error-solved-by-using-old-connect-sythax-why/3
                          https://stackoverflow.com/questions/61879664/qobjectconnect-not-working-signal-not-found-with-function-syntax

                          I'll still dig at it as I don't like these old macros, but at least they work! whhh

                          1 Reply Last reply
                          0
                          • S Offline
                            S Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on 28 Jan 2022, 20:36 last edited by
                            #13

                            Libraries that are shared between plugins and executable shall be shared and not static. Otherwise you will end up with multiple definition of the static meta object of your QObject based classes which is not good.

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            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