Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

XCode Primer

Posted on 2004-08-20
7
565 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
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.
0
 
LVL 23

Expert Comment

by:brettmjohnson
ID: 11856162
0
 
LVL 1

Author Comment

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

-Matt
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 23

Expert Comment

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


0
 
LVL 1

Author Comment

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

-Matt
0
 
LVL 23

Accepted Solution

by:
brettmjohnson earned 145 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:

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

0
 
LVL 1

Author Comment

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

-Matt
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

Title # Comments Views Activity
Folder Comparison 12 54
Change owner from userA to server Local Administrators 7 66
Sed question 2 102
I could not set window to top 4 21
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

839 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