Sign in to follow this  
Dave Eberly

Mac OS X Lion environment variable problem

Recommended Posts

Dave Eberly    1173
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.

Share this post


Link to post
Share on other sites
ApochPiQ    23003
I'm going to try my damnedest to keep my personal opinion about Apple out of this, and just leave you this link instead: [url="http://stackoverflow.com/questions/6770411/mac-os-x-lion-no-longer-recognizes-environment-plist"]http://stackoverflow.com/questions/6770411/mac-os-x-lion-no-longer-recognizes-environment-plist[/url]

Share this post


Link to post
Share on other sites
_the_phantom_    11250
[quote name='ApochPiQ' timestamp='1311488801' post='4839499']
I'm going to try my damnedest to keep my personal opinion about Apple out of this, and just leave you this link instead: [url="http://stackoverflow.com/questions/6770411/mac-os-x-lion-no-longer-recognizes-environment-plist"]http://stackoverflow...vironment-plist[/url]
[/quote]

From that link;

[quote]
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?

Share this post


Link to post
Share on other sites
Dave Eberly    1173
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.

Share this post


Link to post
Share on other sites
Dave Eberly    1173
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.

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this