Re: Linker error multiple definitions

From: E. Robert Tisdale (E.Robert.Tisdale_at_jpl.nasa.gov)
Date: 11/18/03


Date: Tue, 18 Nov 2003 08:29:53 -0800

Andrew wrote:

> I am receiving a multiple definition error from the linker
> when I try to build a project I am working on.
> The message states that the functions I that defined
> within an external .c source file are already defined
> in the main program .obj file.
> I declared the functions in separate header files

Are you sure that you didn't actually *define* the function
in the header files?

> and used the pre-processor conditional #ifndef FILE_H
> to make sure each header is only included once.

But your compiler isn't complaining about multiple *declarations*.
It is complaining about multiple *definitions*.
You can *declare* a function multiple times
but it should only be *defined* once.

> Each .c source file includes the associated header as does the
> main .c file which calls the functions. I know I have done this before
> without any problems, but am I missing a step? Thanks for any help.



Relevant Pages

  • Re: Linker error - fooView.obj LNK2005: _IID_IProvideTaskPage already defined in fooDoc.obj
    ... declarations, one in the document and one in the view. ... multithreaded libraries would refer to symbols in the single-threaded and multithreaded ... Unless someone in the header files is ... Look for simple solutions first. ...
    (microsoft.public.vc.mfc)
  • Re: Ahead of "main"?
    ... The latter style is effectively required when you move to multi-file projects, and the standard practice is to put all of your function declarations in header files so that each source file can simply #include the appropriate header files and then use whatever functions are needed. ... Actually, you should not put *all* your function definitions in header files, since generally there are some which should be local to a given source file and declared static in that source file. ...
    (comp.lang.c)
  • Re: [patch 1/3] epoll cleanups - epoll include diet ...
    ... and it certainly needs to have those syscall's prototypes in scope. ... Ack about signal.h, I forgot about the pwait code:( ... So that the compiler can verify that our declarations of sys_epoll_foo ... include in .c the header files which provide the stuff ...
    (Linux-Kernel)
  • Re: multifile project
    ... Is the project large enough for multiple header files ... file and compiling a .c file just including the ... in the same object file. ...
    (comp.os.linux.development.system)
  • Re: passing structures among functions
    ... I used 'wget' to grab the GIF, so if there's any malicious code on that Web page, I didn't encounter it. ... Give the struct a tag, such as "struct data", and use that instead. ... "Header files should only contain declarations." ...
    (comp.lang.c)