Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Duke Leto

macrumors regular
Original poster
Mar 17, 2008
166
0
I made a project in C that was a "command line tool" in XCode. It uses GLUT/OpenGL, so it does have a user interface. It works fine, and I can run it from Terminal, but I was wondering if there was any way to allow it to run from Finder.

I did create a new target (a Cocoa application), and I included the linked frameworks and removed the prefix header and it compiles and runs. However, it won't work from Finder. I think that the problem is that my program relies on a file named "Input" that it assumes is in its directory. I tried using
Code:
FILE* data = fopen("../../Input", "r");
instead of
Code:
FILE* data = fopen("Input", "r");
but that didn't work. (I also tried more levels of up and down, that doesn't seem to work either.)

I hope that that ramble was half-intelligible!

Thanks in advance for any help.
 

chown33

Moderator
Staff member
Aug 9, 2009
10,756
8,445
A sea of green
In both cases of fopen(), you are assuming a particular value for current working directory, and from which your relative pathnames are assumed to be sensible.

I suggest checking your assumption of working directory, perhaps by NSLog()'ing the actual value, such as returned by the C function getcwd(). You should read the man page for getcwd() to see what its parameters are.
 

Duke Leto

macrumors regular
Original poster
Mar 17, 2008
166
0
I looked into getcwd, and I was able to get the directory of the executable. I wrote some code to modify the path to go up a couple of folders, and I verified that it did the correct modifications. Furthemore, I found that the program worked just fine when I opened the package contents of the .app file and ran the executable inside the MacOS folder from Terminal.
However, the .app will not run from Finder.
 

chown33

Moderator
Staff member
Aug 9, 2009
10,756
8,445
A sea of green
I looked into getcwd, and I was able to get the directory of the executable. I wrote some code to modify the path to go up a couple of folders, and I verified that it did the correct modifications. Furthemore, I found that the program worked just fine when I opened the package contents of the .app file and ran the executable inside the MacOS folder from Terminal.
However, the .app will not run from Finder.

Running the executable using Terminal, after cd'ing into the .app Contents/Resources is not the same thing as running it from Finder.

You should look at the working directory when run from Finder, using the debugger if you have to.

You're making a faulty generalization based on what happens in Terminal. In particular, I can almost guarantee that launching from Finder DOES NOT set the working directory to the location of the executable.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.