[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: problem with linkage
From: |
Paul Pluzhnikov |
Subject: |
Re: problem with linkage |
Date: |
Sun, 16 Apr 2006 12:02:21 -0700 |
User-agent: |
Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.4 (Jumbo Shrimp, linux) |
"k0mp" <Michel.Al1@gmail.com> writes:
> I've got a problem to compile my program (on Linux).
No, you didn't. You got a problem *linking* your program.
> /tmp/ccfRzJFM.o:(.bss+0x40): multiple definition of `program_name'
The problem is as follows: in eht_lib.h, you have:
char *program_name;
When any file including this header is compiled, it gets a
*definition* of "program_name":
g++ -c test.cc eth_lib.cc
nm -A test.o eth_lib.o | grep ' program_name'
test.o:00000000 B program_name
eth_lib.o:00000000 B program_name
So you have two definitions, but you can have at most *one* such
definition.
To correct this, change 'char *program_name;' to
'extern char *program_name;' in the eth_lib.h and add
'char *program_name;' to the eth_lib.cc.
This way there will be one definition in eth_lib.o, and all other
uses will result in a reference to that one-and-only definition.
Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.