• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: ld: duplicate symbol
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ld: duplicate symbol


  • Subject: Re: ld: duplicate symbol
  • From: Bill Bumgarner <email@hidden>
  • Date: Tue, 30 Sep 2008 13:05:39 -0700

On Sep 30, 2008, at 11:21 AM, Claus Atzenbeck wrote:
On Tue, 30 Sep 2008, Nick Zitzmann wrote:
How have you declared CAPersonSwitchKey in the header file?
int CAPersonSwitchKey = 0;

Making this static solved the problem.

Solved which problem? Making your code compile or making it work?

Declaring CAPersonSwitchKey as 'static' in every source file is, at the least, a small waste of memory. In the worst case, it won't do what you want -- if you change CAPersonSwitchKey in a code path in one source file, the other source files that declare the same static will not see the new value.

Consider:

main.m:
static int bobO = 42;
int main (int argc, const char * argv[]) {
    printf("bobO: %d\n", bobO);
    doFred();
    bobO = 43;
    printf("bobO: %d\n", bobO);
    doFred();
    return 0;
}

fred.h:
extern void doFred();
fred.c:
static int bobO = 42;
extern void doFred()
{
    printf("fred: %d\n", bobO);
}

When run, this spews:

bobO: 42
fred: 42
bobO: 43
fred: 42

b.bum


Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: ld: duplicate symbol
      • From: Claus Atzenbeck <email@hidden>
References: 
 >ld: duplicate symbol (From: Claus Atzenbeck <email@hidden>)
 >Re: ld: duplicate symbol (From: Nick Zitzmann <email@hidden>)
 >Re: ld: duplicate symbol (From: Claus Atzenbeck <email@hidden>)

  • Prev by Date: Release build wrong executable name, but debug build it correct
  • Next by Date: Re: Release build wrong executable name, but debug build it correct
  • Previous by thread: Re: ld: duplicate symbol
  • Next by thread: Re: ld: duplicate symbol
  • Index(es):
    • Date
    • Thread