Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Qt Creator for shared library on Mac?
I have an existing Qt application that compiles on both Mac and PC with Qt Creator. With the help of the Qt plugin for Visual Studio 2008, I have created a VS 2008 project for the application. The intention was ultimately to create a shared library, and I was able to change the VS 2008 project from creating an application to a shared library by simply changing the project type to produce a dll file instead of an exe (via the project properties).
As usual with Qt applications, the "main" entry point simply creates a QApplication, shows the main window (widget) and execs it:
int main(int argc, char *argv)
QApplication a(argc, argv);
In VS 2008, I was able to turn this into a DLL by simply changing the project type to dll from exe, and changing the suffix accordingly. By adding code for a function that's known by another program, that other program can load the dll, and execute the function. That entry point simply does just what main() does, and so the host program launches the app as a "plugin".
So far, so good, eh?
Well, now I'd like to do the same thing on a Macintosh. Of course, the same source compiles under Qt Creator on the Mac. But although I've done some XCode and Qt Creator application programming on the Mac, I just don't know where to begin. I don't really care if I use XCode or Qt Creator for development, but I basically just need a project that creates a shared library (a dylib) from the source code for the application, and add the few entry points that the host program can call, and again simply launch QApplication, show the main window (dialog), and exec.
Should be pretty simple, but documentation is sparse, and web searching just leads down a lot of rat-holes...
Any help/advice/example projects (either XCode or Creator) would be most welcome!
[EDIT: code formatting, please wrap in @-tags, Volker]
main() is reserved as the entry point of an application. So it makes no sense to have that in a library. This will not work.
I think window lets you get away with that since it internally uses some other method to start up your application.
loladiro last edited by
There is a template/wizard for creating shared libraries within Qt Creator, have a look at that (File -> New File or Project -> Other Project -> C++ library)
goetz last edited by
If you use qmake, just change the template from app (the default) to lib. See the "qmake docs":http://developer.qt.nokia.com/doc/qt-4.7/qmake-project-files.html#id-40996081-42f2-4221-99c8-c97ec528cc7e and the "qmake tutorial":http://developer.qt.nokia.com/doc/qt-4.7/qmake-tutorial.html for detailed information.
Hello and thank you for the responses!
I have had success with this by using Qt Creator to make a shared library project, and then using qmake to create an equivalent XCode project....XCode 3, that is.
I will have to try to see what happens in XCode 4, but I have heard that it's not quite working?
goetz last edited by
You can use Qt Creator on all platforms of course ;-)
Yes, I would like to have just gone with Qt Creator. Originally, I was unable to make the plugin link with the application. Turns out it was a 32-bit app, and Qt Creator insisted on making a 64-bit library. Figured that out sometime after I switched to XCode. Probably will go back and sort it out with Qt Creator, as it's rather a bit nicer than XCode in some ways, with regard to Qt coding... :-)
Now that the 32- vs 64-bit issue is sorted out, I'll probably go back and try Qt Creator again for this project...
Well, we can not really guess at the word size used in an application you want to link against the library you develop with Qt Creator:-)