[Solved]Qt Mac: How to invoke share library without using QLibrary
-
wrote on 21 Sept 2011, 10:10 last edited by
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.
-
wrote on 21 Sept 2011, 11:22 last edited by
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"? -
wrote on 21 Sept 2011, 17:24 last edited by
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.
-
wrote on 22 Sept 2011, 03:26 last edited by
I impetrate for my poor english.
I know I make a mistake now.yes,it work well:
LIBS += -Llib -lmylibbut 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. -
wrote on 22 Sept 2011, 03:34 last edited by
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.
-
wrote on 22 Sept 2011, 23:03 last edited by
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.
-
wrote on 23 Sept 2011, 01:07 last edited by
yes, it work well after copied the *.dylib to Myapp.app/Context/MacOS
1/7