Linker in Xcode

Member
Posts: 49
Joined: 2006.07
Post: #1
I'm having all sorts of trouble with getting the linker to work in Xcode. There are two main problems I've been running into:
1) My project builds and runs fine in development mode, but in deployment mode, I get the following error:
Linking (the path to my game)/build/Deployment/Gravity Wars.app/Contents/MacOS/Gravity Wars
multiple definitions of symbol DrawFuselage()
multiple definitions of symbol DrawRightWing()
multiple definitions of symbol ResizeGraphics(int,int)
This only occurs if I try to add a .cpp file other than main.cpp. I don't have to do anything with #include statements, merely having the .cpp file in the project causes it to working.
I've heard of several other people encountering this sort of error and having it fixed by upgrading Xcode, but I upgraded to version 2.3 and no luck. Any ideas?
2) If I run it in development mode to suppress the linker error, my .cpp files get the wrong addresses for all global variables. The only way I can get them to get the right addresses of global variables included from other files is to #include the .cpp from the .h file, which I'm told you're not supposed to do. Is that actually a problem?

Thanks in advance.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Member
Posts: 49
Joined: 2006.07
Post: #3
Thanks. I still don't know how to resolve the linker error though.
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #4
Follow the advice given in the tips page

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Member
Posts: 49
Joined: 2006.07
Post: #5
No, I was serious, I did go through and change everything very thoroughly. All it does is make it crash from seg faults because all global pointers become NULL in the .cpp files. The tip doesn't directly answer my second question anyway, am I meant to have to #include the .cpp files?
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #6
you should #include the header files, and you may need to add header guards to them like this:

Code:
#ifndef THIS_SOURCE_FILE
#define THIS_SOURCE_FILE

// body of the header

#endif

and change THIS_SOURCE_FILE to a different word in each header.

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Member
Posts: 49
Joined: 2006.07
Post: #7
Yeah, I've been using header guards. The error I'm getting is different. It's just one error message, even though it lists every variable and function in my app, not the hundreds of nested error messages you tend to get from not using header guards.
The reason it was crashing was actually that I wasn't using extern right when I switched to the format onesadcookie's tips said to use. I have it fixed so that it doesn't crash now, but I still get the linker error if I try to compile in Deployment mode. It still only happens when building for Deployment, not Development.
Quote this message in a reply
Member
Posts: 49
Joined: 2006.07
Post: #8
OK, I finally got it working fully. Thansk, onesadcookie, I just didn't understand how you meant to use extern at first.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Lua linker problems ripburger 6 6,421 Apr 24, 2012 04:16 PM
Last Post: OneSadCookie