Multiple definitions error

I'm trying to build a project taht uses strsafe.h. This file is included once in that main file, and another time in a file that the main file includes. That is so because both use strsafe.h. But unfortunately when linking the linker says there are more than one definition for each function used (once in the main file, once in the secondary file).

The include directives are as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Main.c:
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <strsafe.h>
#include "verinfo.h"
#include "params.h"

params.h:
#include <windows.h>

params.c:
#include <stdarg.h>
#include <tchar.h>
#include "params.h"
#include <strsafe.h> 


Any idea what's the problem?
Have you inspected the strsafe.h file? It should be safe for inclusion into multiple c files. This is a microsoft defined header file that comes with the installation of the compiler, I presume?
Did you put inclusion guards around verinfo.h and params.h?

http://www.cplusplus.com/forum/articles/10627/
Yes, all the files have inclusion guards, especially strsafe.h, but no, it is non-standard since i am using mingw.
Are you using your own makefile? This happened to me once because I messed up gcc's syntax and it was compiling and linking every file instead of just compiling each object file.

I fixed it by adding the -c and -o parameters explicitly:

1
2
3
4
5
6
7
8
all : Main.o params.o
    gcc $(CFLAGS) Main.c Main.o -o myprogram.exe

Main.o :
    gcc $(CFLAGS) -c Main.c -o Main.o

params.o :
    gcc $(CFLAGS) -c params.c -o params.o
People actually still write makefiles? x_x
Topic archived. No new replies allowed.