crazy linker errors

in a large program i changed two files, the .h and .cc files in the last of a derived class. no problems. compiles and preforms as expected. no i made some similar changes to another derived class and i am getting heaps of linker errors now:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
.libs/ldu2.o: In function `decode_hamming(unsigned short*, unsigned short*)':
/home/matt/op25/blocks/src/lib/ldu2.cc:181: multiple definition of `decode_hamming(unsigned short*, unsigned short*)'
.libs/ldu1.o:/home/matt/op25/blocks/src/lib/ldu1.cc:190: first defined here
.libs/ldu2.o: In function `decode_reed_solomon(unsigned short*, unsigned short*)':
/home/matt/op25/blocks/src/lib/ldu2.cc:240: multiple definition of `decode_reed_solomon(unsigned short*, unsigned short*)'
.libs/ldu1.o:/home/matt/op25/blocks/src/lib/ldu1.cc:248: first defined here
.libs/ldu2.o: In function `generate_gf()':
/home/matt/op25/blocks/src/lib/ldu2.cc:276: multiple definition of `generate_gf()'
.libs/ldu1.o:/home/matt/op25/blocks/src/lib/ldu1.cc:291: first defined here
.libs/ldu2.o: In function `gen_poly()':
/home/matt/op25/blocks/src/lib/ldu2.cc:303: multiple definition of `gen_poly()'
.libs/ldu1.o:/home/matt/op25/blocks/src/lib/ldu1.cc:318: first defined here
.libs/ldu2.o: In function `__static_initialization_and_destruction_0':
/home/matt/op25/blocks/src/lib/ldu2.cc:61: multiple definition of `recd'
.libs/ldu1.o:/home/matt/op25/blocks/src/lib/./op25_yank.h:109: first defined here
.libs/ldu2.o: In function `std::_Bit_const_iterator::operator*() const':
/usr/include/c++/4.7/bits/stl_bvector.h:288: multiple definition of `index_of'
.libs/ldu1.o:/home/matt/op25/blocks/src/lib/ldu1.cc:104: first defined here
.libs/ldu2.o: In function `decode_rs()':
/home/matt/op25/blocks/src/lib/ldu2.cc:323: multiple definition of `decode_rs()'
.libs/ldu1.o:/home/matt/op25/blocks/src/lib/ldu1.cc:338: first defined here
.libs/ldu2.o: In function `ldu2::~ldu2()':
/home/matt/op25/blocks/src/lib/ldu2.cc:43: multiple definition of `alpha_to'
.libs/ldu1.o:/home/matt/op25/blocks/src/lib/ldu1.cc:107: first defined here
.libs/ldu2.o:(.data+0x0): multiple definition of `pp'
.libs/ldu1.o:(.data+0x0): first defined here
.libs/ldu2.o: In function `ldu2::nac_str() const':
/home/matt/op25/blocks/src/lib/ldu2.cc:64: multiple definition of `gg'
.libs/ldu1.o:/home/matt/op25/blocks/src/lib/ldu1.cc:29: first defined here
/usr/bin/ld: Warning: size of symbol `gg' changed from 52 in .libs/ldu1.o to 36 in .libs/ldu2.o
.libs/ldu2.o: In function `ldu2::frame_size_max() const':
/home/matt/op25/blocks/src/lib/ldu2.cc:57: multiple definition of `bb'
.libs/ldu1.o:/home/matt/op25/blocks/src/lib/ldu1.cc:35: first defined here
/usr/bin/ld: Warning: size of symbol `bb' changed from 48 in .libs/ldu1.o to 32 in .libs/ldu2.o
.libs/ldu2.o: In function `__exchange_and_add_single':
/home/matt/op25/blocks/src/lib/ldu2.cc:49: multiple definition of `data'
.libs/ldu1.o:/home/matt/op25/blocks/src/lib/ldu1.cc:93: first defined here
/usr/bin/ld: Warning: size of symbol `data' changed from 48 in .libs/ldu1.o to 64 in .libs/ldu2.o


any ideas about how to clear this up will be much appreciated.
Well, you haven't shown us the code that's causing the errors, there's no real way for us to know.

The linker is telling you that you're trying to define the same functions twice. For example, there's a definition of decode_hamming(unsigned short*, unsigned short*) at line 181 of /home/matt/op25/blocks/src/lib/ldu2.cc and another definition at line 190 of /home/matt/op25/blocks/src/lib/ldu1.cc. A function can only have one definition; otherwise, how would the linker know which one was intended to be used for a given function call?
im pretty sure the errors are caused by some variables that i inappropriately left global rushing to the testing. it didn't bother anything (compile or or run time) until i tried adding the same functions to another 'sister' class. so i removed some of the variables from the global scope and the amount of errors dropped correspondingly. but three of variables are indexing arrays that are used so much its going to take an effort to get them out of the global scope. the functions that use these three arrays taken out of global are almost 300 lines so i think i had better work on it before posting here. unless you would like to have a look, by all means, i would love any input??
Generally speaking, global variables are evil. You are strongly advised to find alternative ways to pass the data around between your classes.

If you absolutely insist on having global data, you need to have it defined in one translation unit only, and then declaring external linkage to it in other translation units. Look up the extern keyword.
i am in the process of determining if the variables need to be passed or if i can just name them in each function. its confusing me. if i need to pass the values in these arrays i can just use pointers in the parameters. but i don't know if i need to do that though. would you mind taking a peak? is 250 lines of code too much to put here??


Assuming it's properly formatted, to make it readable, then I would think that would be OK. I'd recommend posting it either in the Beginners or General forum, depending on which you think is more appropriate, as I don't think there's anything Unix-specific about what you're asking, and those forums get a lot more posters.
all right. thanks man!
Topic archived. No new replies allowed.