[Solved]Qt Mac: How to invoke share library without using QLibrary
-
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.
-
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.
-
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. -
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.