I have a problem compiling separate module in C with gcc:
basically, i have my header, common.h:
#ifndef COMMON_M
#include<stdio.h>
#define COMMON_M
void print_array(int *a,int n);
void swap(int *v,int i,int j);
#endif
my functions.c with implementations of functions above:
#include "common.h"
void print_array(int *a,int n) {
int i=0;
for(;i<n;++i)
printf( (i==n-1) ? "%d\n" : "%d ", a[i]);
}
void swap(int *v,int i,int j) {
int t=v[i];
v[i]=v[j];
v[j]=t;
}
and my main:
#include "common.h"
void main() {
int a[10]={6,2,0,12,4,3,7,-4,12,7};
print_array(a,10);
qsort_c(a,0,10);
print_array(a,10);
}
if i try compiling funcionts.c as a module ( gcc -c functions.c ) i get this error:
error: redefinition of ‘swap’ error: redefinition of ‘print_array’
would anyone kindly help me understand why? I am declaring a function in common.h and defining it in functions.c! I don't see why this shouldn't work in theory.
Thanks in advance,