Avoiding Linker Error: Multiple Definition
The Types of Compilation Errors
First, let's distinguish between the types of errors: most compilers will give three types of compile-time alerts: compiler warnings, compiler errors, and linker errors.
As in the below program define the variables as extern in Controller.h file and normal declaration Controller.c file, Program should compile and no Link error.
In the header files use the pre-process directives as below,
#ifndef CONTROLLER_LAYER_H
#define CONTROLLER_LAYER_H
your code here.,......
#endif
the above would allow you to include this header file in n number of other files. You might get a linker error when defining variables, see the below example for solution
Controller.h
#ifndef CONTROLLER_LAYER_H
#define CONTROLLER_LAYER_H
#include "stdint.h"
extern char *pui8IncomingBuffer;
extern char *pui8OutgoingBuffer;
void controllerFunc(void);
#endif
The Types of Compilation Errors
First, let's distinguish between the types of errors: most compilers will give three types of compile-time alerts: compiler warnings, compiler errors, and linker errors.
As in the below program define the variables as extern in Controller.h file and normal declaration Controller.c file, Program should compile and no Link error.
In the header files use the pre-process directives as below,
#ifndef CONTROLLER_LAYER_H
#define CONTROLLER_LAYER_H
your code here.,......
#endif
the above would allow you to include this header file in n number of other files. You might get a linker error when defining variables, see the below example for solution
Controller.h
#ifndef CONTROLLER_LAYER_H
#define CONTROLLER_LAYER_H
#include "stdint.h"
extern char *pui8IncomingBuffer;
extern char *pui8OutgoingBuffer;
void controllerFunc(void);
#endif
Controller.c
#include "Controller.h"
#include "ProtocolLayer.h"
char *pui8IncomingBuffer;
char *pui8OutgoingBuffer;
void controllerFunc(void)
{
pui8IncomingBuffer = "{50, 0101,01,02,03,56,}";
}
No comments:
Post a Comment