I\'m getting a lot of \" redefinition of x....x previously defined here\". Please what does this error means?
You need to limit each file from being included only once. You can do this in 2 ways.
1) At the top of your header files put:
#pragma once
Or 2) if your compiler doesn't support that, put at the top/end of your header files:
#ifndef _MYFILE_H_
#define _MYFILE_H_
...
#endif
Replace MYFILE with the name of your file, and replace ... with the contents of the header file.
You are probably including a header file twice. Make sure your header files are surrounded by #ifndef
statements.
http://www.fredosaurus.com/notes-cpp/preprocessor/ifdef.html
The same thing just happened to me and it was because I accidentally included the .c/.cpp file (within it) instead of the header file.
That would definitely get you a lot of that error.
The error means that there is a symbol that has been defined in one place and an alternate definition has been made in another place.
This can occur if in cases like:
In this last case there will be a mismatch between the real function and the "implicit declaration" that the compiler assumes when it doesn't have a prototype to use.
These situations can be avoided by:
static
, or unique if they are used between object files)extern
statements in source files to declare prototypes. Better to use a prototype from the appropriate header file.static
functions, or in a header file if they are to be used by other object files.