I need to build my plugin/library as a .so on Mac. That happens without extra trick on Linux and works like a charm.
What extra options I need to add to my .pro file?
CONFIG += debug
QT += xml
TEMPLATE = lib
TARGET = mylib
DEPENDPATH += .
macx:INCLUDEPATH += ../../../Test \
/usr/local/include/
macx:LIBS += -L../../../Test/lib
DEFINES += CORE_EXPORT=
DEFINES += GUI_EXPORT=
HEADERS += test.h testGui.h
FORMS += testGui.ui
SOURCES += test.cpp testGui.cpp
RESOURCES += test.qrc
The “.so” suffix doesn’t mean anything on OS X. On an ELF platform like Linux, an “*.so” file is a shared library. On OS X, shared libraries have the “.dylib” extension. On Linux, plugins are implemented as shared libraries (*.so) because you can unload them again when you’re done with them. On OS X, shared libraries cannot be unloaded. That makes them unsuitable for plugins.
On OS X, you use bundles instead of shared libraries in order to implement plugins. Last time I looked, qmake doesn’t support this directly. But you can modify the linker flags in order to build a bundle. By default, qmake uses the “-dynamiclib” linker flag, which builds a *.dylib. Instead, you should use the “-bundle” flag, which builds bundles. You can try this:
The file extension of a bundle is not standardized. You can use whatever you want (.so, .dylib, .plugin, .donald_duck, …) Apple recommends “.bundle”, but doesn’t enforce it. To control the filename of the created bundle, you can set
QMAKE_EXTENSION_SHLIBandQMAKE_PREFIX_SHLIB. For example, to getmylib.bundle, set:If instead you want to get
libmylib.so, only set:As the names suggest,
QMAKE_EXTENSION_SHLIBcontains the file extension (without the.), andQMAKE_PREFIX_SHLIBcontains the file prefix (by default it’slib).