I'm working in C and this is the first time I've coded in C in quite a while. I'm having trouble finding out why I'm getting a multiple definition error on compile. Here's some example code, which is just enough code to reproduce the error.
file: main.c
#include <stdio.h>
#include "struct.h"
int main()
{
parse();
}
file: struct.h
#ifndef STRUCT_H
#define STRUCT_H
#define plantot 4
void parse();
struct planettype
{
char name[30]; // Name of planet
};
struct planettype planname[plantot] = // List of planet types
{ // Name
{"None"},
{"Gas Giant"},
{"Earth-like"},
{"Uninhabitable"}
};
#endif // STRUCT_H
file: parse.c
#include <stdio.h>
#include "struct.h"
void parse() {
printf("I'm not parsing a thing!\n");
};
I try to compile that code and I get:
mingw32-gcc.exe -Wall -g -c C:\Projects\TW-test\parse.c -o obj\Debug\parse.o
mingw32-g++.exe -o bin\Debug\TW-test.exe obj\Debug\main.o obj\Debug\parse.o
obj\Debug\parse.o:parse.c:(.data+0x0): multiple definition of `planname'
obj\Debug\main.o:main.c:(.data+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
I have header guards in place which should prevent this exact thing from happening. Why is it happening anyway? I've spent hours trying to figure this out and can't. In my actual full project, I'm getting this on several structures in struct.h, but I figure if I can fix it for this one, it'll fix it for all of them. If it makes any difference, I'm using Code::Blocks to write and compile the code.
What am I missing? Why won't this code compile?