I'm writing a c program. It contains following files:
A.h
#pragma once
extern int a;
A.c
int a = 1;
B.h
#pragma once
#include "A.h"
B.c
#include "B.h"
And the makefile looks like that
makefile:
objects = A.o B.o
main : $(objects)
cc -Wall -o main $(objects)
When I use 'make' command, there is error 'duplicate symbol _a in A.o B.o'. I searched for similar problems, but it seems that in all such problems, the key is that they didn't use the 'extern' key word. And I use it. What is wrong with my program?
rm A.o B.o
). and callmake
again. What do you see? – Antti Haapala -- Слава Україніclean
target in yourMakefile
– Basile Starynkevitchcmake
or a higher level tool than make. – pimcmake
later. – Owen