• 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: Why am I always getting the linker error: 'duplicate symbol'...?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why am I always getting the linker error: 'duplicate symbol'...?


  • Subject: Re: Why am I always getting the linker error: 'duplicate symbol'...?
  • From: Jesper Storm Bache <email@hidden>
  • Date: Mon, 21 Sep 2009 14:18:46 -0700
  • Acceptlanguage: en-US
  • Thread-topic: Why am I always getting the linker error: 'duplicate symbol'...?

"In C, the default storage class of a non-local c o n s t is extern
and in C++ it is static."
(the quote is from: http://www.research.att.com/~bs/examples_short.pdf)
My guess is that your "other" application may have used C++.

Therefore when you declare a const variable in a header in C you
create storage in each compilation unit (.m or .c file) that you
include the header in.
Multiple storage for the same name => duplicate symbols linker error.

You could possibly simply prefix your const declaration with "static"
as in "static const unsigned x = 123;". THis still creates storage,
and if you want compile time only constants, then you may consider
staying with define or using a C++ compiler.

Jesper

On Sep 21, 2009, at 1:19 PM, Frederick C. Lee wrote:

> I'm trying to replace #define directives with c datatype
> directives.Example:
>
> (1) #define x 123
>
> versus...
>
> (2) const unsigned x = 123;
>
> I place this at the top of the .h (or .m) file, outside of any class
> or
> method as stand alone.
>
> However, every time I try to use the (2) declaration (within a .h
> file) the
> linker gives the error: 'duplicate symbol _x in ....'
>
> I tried placing the (2) declaration at the top of a .m or .c file,
> but I get
> the same linker error.
>
> I've declared global constants in another application without a
> problem.
>
> I've checked the compiler type within the build: gcc 4.2
>
> What am I doing wrong?
> _______________________________________________
>
> 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

_______________________________________________

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

References: 
 >Why am I always getting the linker error: 'duplicate symbol'...? (From: "Frederick C. Lee" <email@hidden>)

  • Prev by Date: Re: Why am I always getting the linker error: 'duplicate symbol'...?
  • Next by Date: Re: Tablet events from ordinary touchpad?
  • Previous by thread: Re: Why am I always getting the linker error: 'duplicate symbol'...?
  • Next by thread: Re: Why am I always getting the linker error: 'duplicate symbol'...?
  • Index(es):
    • Date
    • Thread