Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Mac, Static lib, Dynamic lib Lost signals!

    General and Desktop
    static staticlibrary dynamic dynamiclibrary mac
    2
    13
    417
    Loading More Posts
    • 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
      Dariusz last edited by

      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 Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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 Reply Quote 1
        • D
          Dariusz last edited by

          @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 Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            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 Reply Quote 0
            • D
              Dariusz @SGaist last edited by

              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 Reply Quote 0
              • SGaist
                SGaist Lifetime Qt Champion last edited by

                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 Reply Quote 0
                • D
                  Dariusz @SGaist last edited by Dariusz

                  @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 Reply Quote 0
                  • SGaist
                    SGaist Lifetime Qt Champion last edited by

                    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 Reply Quote 0
                    • D
                      Dariusz last edited by

                      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 Reply Quote 0
                      • D
                        Dariusz @Dariusz last edited by

                        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 Reply Quote 0
                        • D
                          Dariusz @Dariusz last edited by Dariusz

                          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 Reply Quote 0
                          • D
                            Dariusz last edited by

                            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 Reply Quote 0
                            • SGaist
                              SGaist Lifetime Qt Champion last edited by

                              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 Reply Quote 0
                              • First post
                                Last post