Mac OS X Lion environment variable problem

Started by
3 comments, last by Dave Eberly 12 years, 8 months ago
I have a file ~/.MacOSX/environment.plist that contains an environment variable (named WM5_PATH for what it is worth). Running on Mac OS X Snow Leopard (10.6) and previous with Xcode 3.x, my code makes a call to getenv("WM5_PATH"), and I use the returned string for setting path information in my applications. Worked just fine. I just upgraded to Mac OS X Lion (10.7) and Xcode 4.1. Now the call to getenv("WM5_PATH") returns a null pointer. Anyone else struggling with this problem and might have a solution for me? Thanks.
Advertisement
I'm going to try my damnedest to keep my personal opinion about Apple out of this, and just leave you this link instead: http://stackoverflow.com/questions/6770411/mac-os-x-lion-no-longer-recognizes-environment-plist

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]


I'm going to try my damnedest to keep my personal opinion about Apple out of this, and just leave you this link instead: http://stackoverflow...vironment-plist


From that link;


I ran into the same issue today. I called Apple Support and after being escalated to a Senior Advisor, then to her supervisor, I was told that they no longer support environment.plist and that there is no officially-supported method for defining environment variables in Mac OS 10.7.
[/quote]

Wow... just... wow.... why do Apple seem to have developers so much?
Thanks for the replies and link. I make my code available to folks on Windows/Mac/Linux, so I try not to be judgmental about any of those platforms or the tools on them. I must say, though, that the user experience for moving to Mac OS X Lion has been abysmal. Even trying to purchase the OS for download was difficult. I could find no link at the Mac App Store such as "add to cart", "purchase now". There was an icon on the advertisement page with the label "$29.99" and a drop-down list with two items ("Copy Link", "Send to Friend"). I finally discovered that by clicking the "$29.99", the icon changed to "Buy App". I suppose Apple prides itself on a large base of folks who somehow know these things, and the rest of us have to figure it out.

The environment.plist file is processed when I launch a terminal window, although it is not clear whether launching the window causes the processing or when I actually log in to my machine. In the terminal window, the command "set" shows my environment variables, including the WM5_PATH I have listed in environment.plist. I wrote a small test program (using vi and compiling from command line with gcc) that calls getenv("WM5_PATH") and then prints the result to cout. This worked. So as the stackflow link says, apparently you cannot get to the environment from within a GUI app. I had searched Apple's site and found something about accessing the environment through function calls pertaining to Cocoa. I have been reluctant to spend time on writing a shallow Cocoa layer, but maybe this is where Apple wants to push its developers. My next effort is to shell out through a "system(...)" call and hope I can get to the environment information. Short of that, I'll have to include in my installation/release notes that Mac users must edit my file with 'main' and hard-code where WM5 is installed.

All my graphics code is broken. I had been using AGL/Carbon/DrawSprockets (code not written by me originally), and just ignored many of the deprecation warnings. The frameworks that come with Xcode 4.1 now omit a lot of the font handling that used to work, and some basic graphics support (GWorld, Graf stuff) now appears to be accessible only via Cocoa or CGL. Searching Apple developer site for remedies to the AGL issues, I did not find much other than some Apple folks suggesting several hacks. Once again, it appears that Cocoa is the only choice for development. I did hack together a GLUT renderer as a short-term replacement for my AGL renderer. This appears to work (not all my samples are tested yet), but I had to hard-code the string in my path system that should be returned by getenv("WM5_PATH").

Just an old dog not wanting to learn new tricks, but perhaps I have to bite the bullet on this one and learn Cocoa/ObjectiveC/Quartz, and whatever else it takes to get a renderer/application layer to run properly on the Mac.
This is ugly, but appears to work. I created a file wm5path.txt with the path to my installation, placed the file in .MacOSX off my home directory. I could have parsed environment.plist instead, but wanted something simple. Application::WM5Path is a std::string.


if (system("cp ~/.MacOSX/wm5path.txt .") == 0)
{
std::ifstream inFile("wm5path.txt");
if (inFile)
{
getline(inFile, Application::WM5Path);
inFile.close();
}
}

This topic is closed to new replies.

Advertisement