I’m doing a project for school, so I need to compile it with:
gcc hide.c stegano.c -o hide -ansi -pedantic -Wall -Werror
But then I get this errors:
/tmp/ccDME1jC.o: In function `calculate_n':
stegano.c:(.text+0x0): multiple definition of `calculate_n'
/tmp/ccQxPZJu.o:hide.c:(.text+0x0): first defined here
/tmp/ccDME1jC.o: In function `tam_msg':
stegano.c:(.text+0x87): multiple definition of `tam_msg'
/tmp/ccQxPZJu.o:hide.c:(.text+0x87): first defined here
/tmp/ccDME1jC.o: In function `insere_msg':
stegano.c:(.text+0xe1): multiple definition of `insere_msg'
/tmp/ccQxPZJu.o:hide.c:(.text+0xe1): first defined here
/tmp/ccDME1jC.o: In function `copia':
stegano.c:(.text+0x201): multiple definition of `copia'
/tmp/ccQxPZJu.o:hide.c:(.text+0x201): first defined here
/tmp/ccDME1jC.o: In function `esconde_msg':
stegano.c:(.text+0x274): multiple definition of `esconde_msg'
/tmp/ccQxPZJu.o:hide.c:(.text+0x274): first defined here
collect2: ld returned 1 exit status
The program code is like this, I think that the error is probably in the include’s so I hid the actual code:
The program hide.c is like this:
#include <stdio.h>
#include <stdlib.h>
#include "stegano.c"
//code//
Then it calls stegano.c, that contains all the actual function used in hide.c:
#include <stdio.h>
#include <stdlib.h>
#include "stegano.h"
//code//
And the header file stegano.h:
#include <stdio.h>
#include <stdlib.h>
#define MAX 100
typedef unsigned char Byte;
void calculate_n(char name[MAX], int* n, int* x);
int tam_msg(char name[MAX]);
void insere_msg(int size, char name[MAX], Byte* v);
void copia(Byte* v1, Byte *v2, int size);
void esconde_msg(Byte* msg, char name1[MAX], char name2[MAX]);
Thanks for helping!
Caused by this:
this will pull all the function definitions in
stegano.cintohide.c. Meaning thestegano.candhide.cnow define the same functions. This will produce the multiple definition errors you see when you attempt to (compile and) link.Include the header file instead: