Archive

Posts Tagged ‘Xcode’

Xcode and static libs

October 19th, 2009

I’m writing this blog entry just in case other people come across the same problem and can’t seem to figure out what’s going on.

I found it in Xcode 2.5 that hasn’t been fixed in the latest version of Xcode that I have, version 3.1.3.

The bug I’m referring to is when you create a target as a static lib output, then you change the target later to output a dylib. The problem is that everything looks fine… heck, it even puts a dylib in the file name extension, but the file is actually a static library.

You have to go to Terminal.app and use the file command to see that the file is in fact, a static lib and not a dylib. You may not notice the problem at first until you go to debug the project and notice some weirdness.

Hopefully, you haven’t gotten bit by this problem, but if you have, the only solution I found was to create a new target from scratch.

Jaime Coding, Not-so-funny , , , , ,

Xcode 3.1, Perforce and Scripts

March 9th, 2009

In my previous post, I showed how you can leverage AppleScript to check out a file or a project that resides on a Perforce server. The reason for this is that Xcode 3.x does not work well with Perforce.

Now, I figured out how to do this with the build in scripts menu in Xcode. The limitations I found so far is that you can only check out a file, can’t do a project yet, and that the cursor has to be in the file that you want to check out.

So I created a script, named it “Check out file” and put it in a section named “Gravy” since that is what I work with most. The script code is:

#!/bin/sh
# This shell script checks out the current file from Perforce, so long as it has the cursor in it
 
# Get the file's full path
FULL_FILE_PATH="%%%{PBXFilePath}%%%"
 
# Check to make sure it exists
if [ -f "$FULL_FILE_PATH" ]
then
	# Separate the filename and the path
	SRC_FILE=${FULL_FILE_PATH##*/}
	FILE_PATH=${FULL_FILE_PATH%/*}
 
	# Go to the folder and invoke the p4 command line app with the appropriate arguments
	cd "$FILE_PATH"
	/usr/local/bin/p4 -cjrios_My_Perforce_ClientName -pperforce.jaimerios.com:1666 -PHah -ujaimer edit "$SRC_FILE"
 
# This is a hack to get Xcode to recognize that the file was checked out
# Notice that the code is not indented
osascript - "$1" << ENDOFSCRIPT
tell application "Xcode"
	set myFile to associated file name of front window
	save myFile
end tell
tell application "Finder"
	activate
end tell
tell application "Xcode"
	activate
end tell
ENDOFSCRIPT
 
else
	echo File not found:"$SRC_FILE"
fi

For the output and error options, I set them to “Display in Alert”.

And that’s it. I hope this helps you and if you have any comments for improving this, post a comment and let me know.

Happy coding!

Reference:
Xcode shell scripting

Jaime Coding , ,

Xcode 3.1 and Perforce

March 7th, 2009

I use Perforce and I love it! Over the years I’ve used Visual SourceSafe, CVS, SVN and I experimented with other tools, but none of them have come close to the usefulness of Perforce.

I also use Xcode for my Mac coding but when you use Xcode with Perforce, you get some wierd behaviour. Xcode get’s hung, for no reason whatsoever and although Apple seems to know this is a problem, it doesn’t seem like they are fixing this problem any time soon.

Lucky for me you can use AppleScript from within Xcode! I usually work on one project at a time, so I can create an AppleScript that checks out the frontmost project file for me and another AppleScript to check out the currently selected source code file.

When you open Xcode you’ll notice an AppleScript icon in the menubar between Window and Help, but this is not an AppleScript drop down. This is just for the General Scripts that can be invoked from Xcode. So, if you want to run a shell script from Xcode, you can use this scripts menu for doing that, but for me, I wanted to leverage AppleScript for what I want to do.

You think this is for AppleScript, but it's not.

So, to make the AppleScript menu available, you have to open the AppleScript Utility in “/Applications/AppleScript/”. Open that program and click the “Show Script menu in menu bar” checkbox.

Use this to make the Script menu available

Once you do that, you should see an AppleScript menu item by the other icons on the left side of your menubar.

Now, open the “Script Editor” program within the “/Applications/AppleScript” folder. Copy the code below, which attempts to check out the frontmost project file from Perforce:

?View Code APPLESCRIPT
-- Check out the frontmost project
tell application "Xcode"
set myProj to (active project document)
set myCmd to full path of myProj
end tell
 
set myCmd to "/usr/local/bin/p4 -cjrios_My_Perforce_ClientName -pperforce.jaimerios.com:1666 -PHah -ujaimer edit " & myCmd & "/..."
 
do shell script myCmd

Basically, the script gets the frontmost project file, sets a variable to the full path to the project file and then I create a string with the command that I would normally invoke in Terminal.app. The changes you need to make to the command line are:

  • The -c option which tells p4 which client you are working in
  • The -p option which is the name, or ip, with TCP port to the perforce server
  • The -P option which is your password to the server and
  • The -u option which is your username

Notice that I don’t have a space between the switch and the value and that I have the full path to p4 spelled out.

Paste the code into a new script in “Script Editor” and save the script, with the name of your choice, into the “/Users/jaimerios/Library/Scripts/Applications/Xcode” folder. Once you go back to Xcode, you will see your script in the menu item.

Now the following script is almost the same thing, except for it checks out the current file that is selected in the project. Repeat the same steps for creating the project check out script for the script code below:

?View Code APPLESCRIPT
-- Check out the currently selected file
tell application "Xcode"
 
set myFile to associated file name of front window
set textDocuments to text documents
repeat with i in textDocuments
if path of i is myFile then
 
set myCmd to path of i
set myCmd to "/usr/local/bin/p4 -cjrios_My_Perforce_ClientName -pperforce.jaimerios.com:1666 -PHah -ujaimer edit " & myCmd
do shell script myCmd
end if
end repeat
 
end tell

I hope these scripts help you out. If you have any suggestions for making these scripts better, post a comment and let me know.

Happy coding!

Jaime Coding , ,

Weird EXC_BAD_ACCESS error with NSPopAutoreleasePool

February 25th, 2009

Recently I worked on a project that had a NIB and XIB in it and for some strange reason I was getting a EXC_BAD_ACCESS error message in GDB with NSPopAutoReleasepool being the culprit. The best part about the problem was that the only indicator I had for the call stack was was four question marks ‘????’. That didn’t make too much sense.

Luckily, I came across this posting on cocoadev: click here

The point to the article was how to intelligently look at the error and get a call stack from code that is normally hidden from you in Cocoa. This article shows you how to turn on those extra debugging options so that you can figure out where you are causing the problem.

In my case, I was double-free-ing an object that was already being handled by NSAutoreleasePool.

Jaime Coding , , ,

I just learned something magical!

November 14th, 2008

I use Xcode 3.1.1 at work and it does not work well with Perforce, which is sad because I really love Perforce.

So, I have been using an application that a co-worker told me about called DTerm to help me check out files held in Perforce. This program is a great utility in that it allows me to invoke a command from anywhere in the Mac OS or in any program. If I have a file selected in a Xcode project and then I bring up DTerm, I can type “p4 edit” then hit Cmd+Shift+V to enter the name of the file I have highlighted. Hooray!

However, you can’t do this with project files. Xcode won’t let you select the project file so that you can check out the file, which is actually a folder in disguise. Boooo!

For each of my projects, I have a folder for the platform I am targeting. So for the Mac, I have a folder named “mac” which has my project file, objects and output binaries. A lot of times I check out the entire directory using P4V since I need to overwrite the libraries that are in there.

Today, I discovered how you can check a directories contents in one fell swoop: “p4 edit …”. Oh. My. God! This is great! This is awesome! You don’t know how much time I just saved by doing that!

If you get anything out of this entry is that “p4 edit …” is awesome. Now don’t abuse that power or you’re liable of getting into trouble.

Happy coding!

Jaime Coding , , , , ,

Just when you thought things would work… crash!

October 21st, 2008

I work on large projects that are sometimes too unweildy to debug. The compile times are too long, the apps can take a while to load and when you’re looking to test something quickly, you don’t want to have to sit at your desk and wait for the IDE to finish what it’s doing.

So, to speed things up, I usually write tiny applications that I use for testing. Although they litter my file system, they are much faster to use and much easier to debug than an entire solution.

They are nice… until they break. I have a 64-bit mini application that I’ve been using to test my code with and it’s been working fine, until I went to use it yesterday. Now, so many things have changed on my computer that I can’t say that there is a single thing I can pinpoint to show why this application is not working.

So, instead of trying to figure out what’s wrong, I build a new project, which is great and all, but now, the IDE doens’t compile or launch a 64-bit version of my test app.

So what is going on here? I don’t know, but I will post the solution once I have it figured out.

Oh, if you’re wondering what IDE I’m referring to, it’s Xcode 3.1.

Jaime Coding, Not-so-funny, What's New , , ,

Dumping symbols from a library

September 4th, 2008

When you need to dump symbols from a dylib on Mac OS or a DLL on Windows, you can use the following commands to do so:

Mac OS

nm -m mySpecialLibrary.dylib

Windows

dumpbin /exports mySpecialLibrary.dll

Now sometimes, you have have a lot of symbols in one library, or you may want to find one particular symbol. On the Mac, that’s pretty simple to do. Just use the grep command to find the symbol you are looking for:

nm -m mySpecialLibrary.dylib | grep someSpecialFunction

On the PC, you can dump your symbols to a file so that you can use a text editor like Notepad++ to search for symbols:

dumpbin /exports mySpecialLibrary.dll > c:\MyProjectFolder\mySpecialLibrarySymbols.txt

Jaime Coding , , , ,

Using OpenMP and Xcode

January 27th, 2008

During my pilgrimage to Apple in Cupertino California last year, I got to meet some really bright developers at a performance workshop. Of the people who were presenting, Intel was there touting OpenMP. Of course, Apple’s Xcode didn’t yet support OpenMP unless you followed some up-the-sleeve tricks: http://alphakilo.com/openmp-on-os-x-using-gcc-42/

Jaime Coding , , , , , , , ,