News:

Download Pelles C here: http://www.smorgasbordet.com/pellesc/

Main Menu

multiply defined

Started by pyzaist, November 06, 2010, 12:44:01 AM

Previous topic - Next topic

pyzaist

Hello. I created a few include files that have a few functions, constants, and type definitions in each. I'm using it in a project that has multiple files, and they are included in all of them. It throws a lot of errors:


QuoteBuilding ray tracer.exe.
POLINK: error: Symbol '_initSDL' is multiply defined: 'event.obj' and 'load.obj'.
POLINK: error: Symbol '_setpix' is multiply defined: 'event.obj' and 'load.obj'.
... like 30 more
POLINK: error: Symbol '_font_writei' is multiply defined: 'event.obj' and 'trace.obj'.
POLINK: error: Symbol '_font_writef' is multiply defined: 'event.obj' and 'trace.obj'.
*** Error code: 1 ***
Done.

I know the problem is that the functions are defined like five times. Is there any way to fix this besides seperating the functions and definitions in every include file?

CommonTater

Two suggestions...  
1) Create a Global header with all the stuff that has to be in every page in it.  I typically do this with windows and library includes.

2) Use guard code in your headers....

// MyInclude.h
#ifndef MYINCLUDE_H
#define MYINCLUDE_H


// put your stuff here


#endif // MYINCLUDE_H


Since your defines are now wrapped in a conditional statement that relies upon MYINCLUDE_H not being defined, each header will now only be read once by the pre-processor.  Of course you would use a unique name, generally the header file name in each one.

Hope that helps...