[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


XCode Primer

Posted on 2004-08-20
Medium Priority
Last Modified: 2013-12-26
Hi all. Got an annoying newbie question for you. So, I've been developing at the command line all my life with gcc and make, but my company just bought me a PowerBook replete with XCode.  So, I figured I'd give it a fair shake, but from opening the application and playing around for a few hours, it's still not obvious to me how to build my old linux source code in it... even though I know it's really just using gcc and doing the same things I normally would with make (I think).   For example, I've got one application written in c that has a main program source file, a header with structs and fucntions used in the main program, a source file with the header's functions in it, and it needs to link to a shared library (which, I gather, are dylib's in OSX):



Needs to link to: libmysqlclient.dylib in /usr/lib/

So, I was hoping someone would be kind enough to walk me through setting up a project that contains these files in the correct arrangement such that when I hit the build button, it builds.  (I.e. what kind of project to I open, how do I answer the dialogues, etc.)

Thanks so much!
Question by:spike3382
  • 4
  • 3
LVL 23

Expert Comment

ID: 11856052
I am assuming your program is a traditional command-line tool
ported from Linux and (at this point) not using Apple-specific toolkits
(like AppKit, CoreFoundation, etc).

- Launch /Developer/Applications/Xcode.app
- Select "File->New Project" from the menu
- Select "Command Line Application - Standard Tool" for the Project Type
- Name the project accordingly "matchd", Put it in the same directory as your source files
- New Project annoyingly creates "main.c" for you, so you might as well delete it now from Project-Source
- Select "Project->Add to Project" from the menu to add the source files
  - Select the source files to add to the project
  - Use CMD-click to select multiple files (CMD is the Apple key next to spacebar)
  - Click the "Add" button after selecting the three source files
  - Specify "Reference Type: Relative to Project"
- Select "Project->Add to Project" from the menu to add the library
  - Type '/' to bring up the hidden "Go To Folder" dialog box (BAD UI. BAD, BAD, UI!!)
  - Complete typing "/usr/lib" in the Go To Folder dialog and Click "GoTo" button
  - Select libmysqlclient.dylib and click the "Add" button
  - Specify "Reference Type: Absolute Path"
- Click the "Build" button and iterate, fixing up build errors.

Author Comment

ID: 11856268
Thanks, Brett.  I'd been wondering about how to get to /usr/lib through the gui.  That is an interesting decision on apple's part.  And yes, it's just a command line tool.

However, I followed your instructions (with a few interpolations... I don't have CommandLine Application - Standard Tool; but I do have Tool - Standard Tool, so I used that.  I also don't have Project->Add to Project but I do have Project->Add File, so I took an educated guess ;-) ), and everything seemed okay.  It compiled with no errors.  However, if I hit Build and Run, it opens a fresh terminal window that stays blank and then the CPU usage goes to 100% and nothing happens.  I modified the program specifically so that it would return artificially quickly with a statement written to the terminal, and still all it does is descend into some infinite loop that I seem to have no control over and takes up 100% CPU forever...  I can compile it with make in the project directory and everything goes swimingly.

Any thoughts on what I'm doing wrong?  Thanks!

(thanks for the references too, by the way).

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

LVL 23

Expert Comment

ID: 11857215
The minor menu differences are probably due to differences in XCode version (I'm at v1.5).

If the program doesn't work ... time to debug it.  On the XCode project menu click and hold
the "Build and Go" icon until a drop-down list appears, then select "Build and Debug".
This will build the debuggable version of the product and pop you into the GUI front end
to gdb.   You can click the "Breakpoints" icon on the Debugger toolbar and add a breakpoint
for main().


Author Comment

ID: 11857408
Yeah, I'm using XCode 1.0, apparently.

I put a breakpoint next to "int main(.." and a few other places, and when I hit build and debug it never got to any of them, which makes me think that perhaps it's not my problem but XCode's?  Do you think this is a bug from using XCode 1.0?  I'm unfamiliar with Apple's upgrade policy... I assume it's free....  

Anyway, if I pause the program durring debug execution, all I get is the list of the contents of the thread on the left.  None of them cause any more information to come up in the right or bottom panes.  It looks like this:

#0      0x8fe26998 in __dyld_thread_self_trap
#1      0x8fe161ac in __dyld_linkedit_error_enter
#2      0x8fe0a360 in __dyld_check_and_report_undefineds
#3      0x8fe11690 in __dyld_link_in_need_modules
#4      0x8fe1124c in __dyld_bind_lazy_symbol_reference
#5      0x8fe01340 in __dyld_stub_binding_helper_interface
#6      0x7fdf0ce8 in findSymbolInSet
#7      0x7fdf0d6c in undefinedHandler
#8      0x8fe0a398 in __dyld_check_and_report_undefineds
#9      0x8fe11690 in __dyld_link_in_need_modules
#10      0x8fe11464 in __dyld_bind_symbol_by_name
#11      0x8fe148b0 in __dyld__dyld_NSLookupAndBindSymbol
#12      0x90045974 in NSLookupAndBindSymbol
#13      0x00001d54 in start
#14      0x00001c70 in start
#15      0x00001ae4 in start

So, I'm not sure if anyone has any intuition on why this isn't working... as I said before this is totally fine code and compiles and runs beautifully from the command line, I don't understand what extra work XCode is doing that's causing it not to be able to run.  If anyone has any intuition on this, I'd be forever grateful.

Thanks for your time!

LVL 23

Accepted Solution

brettmjohnson earned 580 total points
ID: 11857459
It looks like its failing to load the shared library, and hanging trying to report
an undefined symbol error.  This looks like a loader problem or possibly a
problem with the dynamic lib.  Were you supposed to link against some other
library as well?  And yes XCode is free. The latest version is available at:



Author Comment

ID: 11860353
Well, it's working now, and I figured I'd post this incase anyone was having a similar problem.  I upgraded to XCode Tools 1.5, and followed the above steps verbatim and the program compiles and runs great.  So, who knows, I guess XCode v1.0 might have an issue.

Thanks a lot, Brett!  I learned a lot.


Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Screencast - Getting to Know the Pipeline
Suggested Courses

868 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question