Today I was fighting with Qt Creator and environment variables on Mac OSX.
Macintosh has a clean way to encapsulate software: the .app extension is in reality a folder in which are contained resources, the application's executable and other files needed to the application. In this way if you have to uninstall an application you have just to trash this .app container and you have trashed everything. But.
If you want to make a software dependent on something else present in your machine and you want to be portable and cross platform an elegant way is to use environment variable to tell your software where to find its dependencies without the needs to ask other developers to change something in the source code.
In Windows, which leave with distributed pieces of code, was very easy to allow Qt Creator to see the env variable, just put a new custom variable into "System -> Preferences -> Environment Variables", then start Qt Creator and your variable is there.
With Mac OSX you can assign environment variables in different ways for different purposes. The environment used for application is not the environment you get when starting the Terminal application.
For Terminal application, environment variable can be set in the .profile file situated in your home folder (if it is not present you can create it).
Environment for Mac OSX applications is determined at login from the file: environment.plist placed into the .MacOSX folder situated in your home folder (again, if the .MacOSX folder does not exist you can create it and create inside it the environment.plist file).
Now you can edit the file and add your custom variables (by editing the file with Property List Editor application) that will be read from Mac OS applications at login.
I had just to logout and login, start Qt Creator and now magically my custom env variable was there :-)
Thanks for reading and feel free to leave a comment (only registered users) :-)
No comments:
Post a Comment