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]Qt Mac: How to invoke share library without using QLibrary
Forum Updated to NodeBB v4.3 + New Features

[Solved]Qt Mac: How to invoke share library without using QLibrary

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 4.4k 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.
  • S Offline
    S Offline
    szuzsq
    wrote on last edited by
    #1

    1).At MS Window,
    when create a share library, it generate *.dll and *.lib files;
    when create a static library, it generate *.lib


    so, it can both invoke library like this way:
    LIBS += -L"some_lib_path" -lsome_lib


    2).But at Mac OS X,
    when create a share library, it generate *.dylib
    when create a static library, it generate *.a


    I only know to invoke static library like this way:
    LIBS += -L"some_lib_path" -lsome_lib


    but how to invoke share library?


    Using QLibrary, it can resolve the function, method from library:

    @
    QLibrary lib("some_lib");
    typedef void (*some_func)();
    some_func func = (some_func) lib.resolve("some_func_symbol");
    if (func)
    func();
    @

    but it is not simple.

    1 Reply Last reply
    0
    • P Offline
      P Offline
      p-himik
      wrote on last edited by
      #2

      I don't know anything about Mac but "LIBS += -L“some_lib_path” -lsome_lib" works well both on Linux and Windows.
      What errors do you get when there is only .dylib relevant to some_lib in "some_lib_path"?

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #3

        It works the same on shared and static libs on the Mac. Just add

        @
        LIBS += -L/path/to/lib -lmylib
        @

        And just to avoid further confusion - you might not be a native english speaker, so the difference might not be clear: what you want to do, is not to invoke a library, but to link against it.

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0
        • S Offline
          S Offline
          szuzsq
          wrote on last edited by
          #4

          I impetrate for my poor english.
          I know I make a mistake now.

          yes,it work well:
          LIBS += -Llib -lmylib

          but after etest.app generated, it must to
          copy "libmylib.dylib"
          to "etest.app/Contents/MacOS/libmylib.dylib"

          or else it will appear error message:

          Unable to read symbols for "libmylib.1.dylib" (file not found).
          Unable to read symbols from "libmylib.1.dylib" (not yet mapped into memory).
          dyld: Library not loaded: libmylib.1.dylib
          Referenced from: /Volumes/Mac_OS_4/test/library_test/lib/etest.app/Contents/MacOS/etest
          Reason: image not found


          now the new question is:
          Is there any way for me to configure, so that I have not to copy the *.dylib file to "etest.app/Contents/MacOS" when I run under debug model.
          because *.dylib maybe be edited & built frequently.

          1 Reply Last reply
          0
          • P Offline
            P Offline
            p-himik
            wrote on last edited by
            #5

            To make your app able to find your libraries you have to add paths to folders containing them to PATH variable in the Project tab -> Run settings -> Run environment.
            Again, this works at least for Linux and Windows.

            If you want to run your app outside of Qt Creator you should read some manuals about your OS's library finding algorithms.

            1 Reply Last reply
            0
            • G Offline
              G Offline
              goetz
              wrote on last edited by
              #6

              The usual place for shared libraries on a Mac OS X application bundle is MyProgram.app/Contents/Frameworks, you will have to invoke install_name_tool in order to adjust the path to the libs in the application executable.

              http://www.catb.org/~esr/faqs/smart-questions.html

              1 Reply Last reply
              0
              • S Offline
                S Offline
                szuzsq
                wrote on last edited by
                #7

                yes, it work well after copied the *.dylib to Myapp.app/Context/MacOS

                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