Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

XCode: Duplicate symbol linking error?

3 views
Skip to first unread message

petertwocakes

unread,
Nov 15, 2009, 10:40:38 AM11/15/09
to
Hi.

I'm getting the following 1 linking error:
"ld: duplicate symbol _verbInflections in
/Developer/SDW Projects/WordNet2009/build/WordNet2009.build/Debug/
WordNet2009.build/Objects-normal/i386/ParseWordNetFiles.o and
/Developer/SDW Projects/WordNet2009/build/WordNet2009.build/Debug/
WordNet2009.build/Objects-normal/i386/CSynset.o"

The symbol it is referring to is in WordNetDefines.h, which is
included in the two files it is complaining about: ParseWordNetFiles.h
and CSynset.h.
These two headers contain no other includes, nor does
WordNetDefines.h, so I'm pretty sure there's no circular referencing.

If I move the verbInflections type elsewhere as a workaround, it
simply complains about all the other types I've defined in
WordNetDefines.h, though it only ever registers 1 error at a time.

Needless to say, both ParseWordNetFiles.h & CSynset.h do need to
include WordNetDefines.h to recognize my custom types.

I've returned to coding after a long absence, and a cpu, OS, and Xcode
updates, so I could well me missing something really obvious.

Can anyone suggest anything that might cause this error?

Many thanks


Sherm Pendley

unread,
Nov 15, 2009, 12:21:34 PM11/15/09
to
petertwocakes <petert...@googlemail.com> writes:

> I'm getting the following 1 linking error:
> "ld: duplicate symbol _verbInflections in
> /Developer/SDW Projects/WordNet2009/build/WordNet2009.build/Debug/
> WordNet2009.build/Objects-normal/i386/ParseWordNetFiles.o and
> /Developer/SDW Projects/WordNet2009/build/WordNet2009.build/Debug/
> WordNet2009.build/Objects-normal/i386/CSynset.o"
>
> The symbol it is referring to is in WordNetDefines.h

Sounds like you forgot to declare verbInflections as extern in the header,
so the compiler thinks you've defined multiple globally-visible symbols
with the same name - one in each source file that includes the header.

Instead, you want to define it as a globally-visible symbol in one source
file, and use extern in the header so that other source files will refer
to that one rather than defining their own.

For example, in foo.h:

extern int foo;

Then, in foo.(c/m/cc):

#include "foo.h"
int foo;

sherm--

petertwocakes

unread,
Nov 15, 2009, 3:28:54 PM11/15/09
to
On 15 Nov, 17:21, Sherm Pendley <spamt...@shermpendley.com> wrote:

Thanks, I'm sure that is the problem, but unfortunately the type and
variable is more complex and I can't seem to get it to work. ( I guess
I should have posted this in the first place)
Originally, in the header I had this:

struct VerbInflection {
string suffix;
string ending;
} verbInflections[kNumInflections] = {
{"s", ""},
{"ses", "s"},
{"xes", "s"},
{"zes", "z"},
{"ches", "ch"},
{"shes", "sh"},
{"ies", "y"},
{"es", "e"},
{"es", ""},
{"ed", "e"},
{"ed", ""},
{"ing", "e"},
{"ing", ""},
{"er", ""},
{"est", ""},
{"er", "e"},
{"est", "e"},
};


So verbInflections needs to be defined across multiple source files,
but each file that includes it sees it as duplicate.

So I made a new header VerbInflection.h:

struct VerbInflection {
string suffix;
string ending;
}
extern VerbInflection verbInflections;


and the VerbInflection.cpp :

VerbInflection verbInflections[kNumInflections] = {
{"s", ""},
{"ses", "s"},
{"xes", "s"},
{"zes", "z"},
{"ches", "ch"},
{"shes", "sh"},
{"ies", "y"},
{"es", "e"},
{"es", ""},
{"ed", "e"},
{"ed", ""},
{"ing", "e"},
{"ing", ""},
{"er", ""},
{"est", ""},
{"er", "e"},
{"est", "e"},
};

But I get these errors:
error: conflicting declaration 'VerbInflection verbInflections [17]'
error: 'verbInflections' has a previous declaration as 'VerbInflection
verbInflections'


Is there a way to get both the VerbInflection type, and the globally
defined array of verbInflections to be included in any source file
that needs them?

Thanks


Paul Russell

unread,
Nov 16, 2009, 5:50:36 PM11/16/09
to

Change:

extern VerbInflection verbInflections;

to

extern VerbInflection *verbInflections;

Paul

petertwocakes

unread,
Nov 17, 2009, 12:24:07 PM11/17/09
to

Thanks, silly mistake.

0 new messages