I got this error when compiling my code in visual studio and i need help please :
Error LNK2005: _cmd already defined in complex.obj
I have the following C Files :
### File name: Main.c ###
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include "complex.h"
int main()
{
char command[30];
int i;
FOREVER
if (scanf("%s", command) == 1)
{
for (i = 0; cmd[i].func != NULL; i++)/*searcing the relevant function*/
{
if (strcmp(command, cmd[i].name) == 0)
break;
}
if (cmd[i].func == NULL)
printf("Command does not exist: %s\n", command);
else
(*(cmd[i]).func)();
}
}
and this:
### File name: Complex.h ###
#define FOREVER for(;;)
typedef struct complex
{
double real;
double imag;
}complex;
void read_comp(void);
void print_comp(void);
void add_comp(void);
void sub_comp(void);
void mult_comp_real(void);
void mult_comp_img(void);
void mult_comp_comp(void);
void abs_comp(void);
void halt(void);
void empty_string(void);
void stop(void);
struct STR{
char* name;
void(*func)(void);/*pointer to function*/
}cmd[] = {
{ "read_comp", read_comp },
{ "print_comp", print_comp },
{ "add_comp", add_comp },
{ "sub_comp", sub_comp },
{ "mult_comp_real", mult_comp_real },
{ "mult_comp_img", mult_comp_img },
{ "mult_comp_comp", mult_comp_comp },
{ "abs_comp", abs_comp },
{ "halt", halt },
{ "stop", stop }
};
and this:
### File name: Complex.c ###
#include "complex.h"
void stop(void)
{
exit(1);
}
void read_comp(void)
{
printf("read_comp\n");
}
void print_comp(void)
{
printf("print_comp\n");
}
void add_comp(void)
{
printf("add_comp\n");
}
void sub_comp(void)
{
printf("sub_comp\n");
}
void mult_comp_real(void)
{
printf("mult_comp_real\n");
}
void mult_comp_img(void)
{
printf("mult_comp_img\n");
}
void mult_comp_comp(void)
{
printf("mult_comp_comp\n");
}
void abs_comp(void)
{
printf("abs_comp\n");
}
void halt(void)
{
printf("halt\n");
}
void empty_string(void)
{
printf("Empty sting, Please try again\n");
}
We have here some functions that get some parameters as inputs through the command line. The functions implementation is not finished yet. Please i need help with solving the error.