N
N
Nodar2016-01-04 22:13:16
C++ / C#
Nodar, 2016-01-04 22:13:16

Gcc multiple definition of ..., what is the correct way to declare variables that are used in multiple files?

Hello. Added the C++ tag, because the problem is most likely a general one for C and C++. I'm delving into C, I'm not writing on the plus signs yet.
There is a Makefile

config_parser.o: config_parser.c ews.h
  gcc  -c config_parser.c

ews.o: ews.c ews.h
  gcc -c ews.c

ews: config_parser.o ews.o
  gcc --std=c99 config_parser.o ews.o -o ews

The essence of the error, as far as I understand, is that the compiler says that I declare the same variable / macro several times.
How to cure this?
For example, I have a config.h that I include in several files via ews.h and override some values ​​here and there.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Martyanov, 2016-01-04
@Nodar

It's right not to do that. You will say that in one file you have foo = 1, and in another foo = 0. And how does the compiler know where it should be? At what point in time should it change from zero to one? And in general, which of the two is implied in each line of code ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question