[Biococoa-dev] string definitions

Charles PARNOT charles.parnot at stanford.edu
Mon Mar 21 00:42:42 EST 2005

>I was adding the stringdefinitions to some more source files, and ran into a weird build error. I can add #import "BCStringDefinitions.h" to one file (BCSymbol.m in this case), and use the replacement properties for various strings. However, if I then add #import "BCStringDefinitions.h" to the next file (BCAminoAcid.m), I get linker errors such as:
>ld: multiple definitions of symbol _BCSymbolpKaProperty
>/Users/koen/Documents/Development/Active Projects/FrameWorks/BioCocoa/build/BioCocoa.build/BioCocoa.build/Objects-normal/ppc/BCAminoAci<...snip...>
>- Koen.

You can't define the value of a variable in a header and then call that header from multiple file. Otherwise, the compiler creates one variable for each implementation file and each compiled '.o' piece of code. What you are supposed to do is declare those variables in the header using extern, so the linker knows that these variables will exist. And then the values should be set in an implementation file. Constants have to be associated with one particular class. It should probably be in BCSymbol.m.

So the header should have
extern NSString *BCSymbolNameProperty;

and the implementation
NSString *BCSymbolNameProperty=@"Name";

Help science go fast forward:

Charles Parnot
charles.parnot at stanford.edu

Room  B157 in Beckman Center
279, Campus Drive
Stanford University
Stanford, CA 94305 (USA)

Tel +1 650 725 7754
Fax +1 650 725 8021

More information about the Biococoa-dev mailing list