Solved

XCode Primer

Posted on 2004-08-20
7
561 Views
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):

matchd.c

compat.h
compat.c

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!
-Matt
0
Comment
Question by:spike3382
  • 4
  • 3
7 Comments
 
LVL 23

Expert Comment

by:brettmjohnson
Comment Utility
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.
0
 
LVL 23

Expert Comment

by:brettmjohnson
Comment Utility
0
 
LVL 1

Author Comment

by:spike3382
Comment Utility
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).

-Matt
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 23

Expert Comment

by:brettmjohnson
Comment Utility
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().


0
 
LVL 1

Author Comment

by:spike3382
Comment Utility
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!
-Matt

-Matt
0
 
LVL 23

Accepted Solution

by:
brettmjohnson earned 145 total points
Comment Utility
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:

http://developer.apple.com/tools/download/

0
 
LVL 1

Author Comment

by:spike3382
Comment Utility
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.

-Matt
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
sumDigits challenge 9 96
Hibernate methods 2 58
matchUp  challenge 6 48
ShiftLeft challenge 21 65
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now