I need a struct variable declared and defined in a header file to be accessible from more than one source files but I get a linker error. I'm putting small source code here. Linker error is
main.obj : error LNK2005: _a already defined in library.obj
fatal error LNK1169: one or more multiply defined symbols found
header.h
struct Student {
char *FirstName;
char *LastName;
};
struct Student a = {"John", "Jackson"};
library.c
#include <stdio.h>
#include "header.h"
void PrintStudentName(struct Student *name)
{
printf("%s\n%s\n", name->FirstName, name->LastName);
}
main.c
#include <stdio.h>
#include "header.h"
void PrintStudentName(struct Student *name);
int main()
{
PrintStudentName(&a);
return 0;
}