On 25 April 2014 12:21, Gyorgy Kovesdi wrote: > On 2014. April 25. 12:53:54 Markus Trippelsdorf wrote: >> You're violating the "one definition rule". It states that you can >> define the same struct in different translation units, provided it >> consist of the same sequence of tokens, otherwise the behavior is >> undefined as in your example. > > Ok, you are right. > But my problem is that those definitions come from two independent sources > using the same library and do not know each other. C++ namespaces exist to avoid this problem. > I do not see a solution to solve it, but at least detecting this situation > would be useful. > > nm -C a.o b.o > > a.o: > 0000000000000000 T test_a(int) > 0000000000000000 W Checker<test>::mySize() > > b.o: > 0000000000000000 T test_b(int) > 0000000000000000 W Checker<test>::mySize() > > There are two different functions having the same name and parameter list: why > the linker do not send at least a warning message about it? If I define such > (e.g. other test_a() function again) then it results in a linker error. Why > those mySize() functions not? Because test_a is not a template. It is normal for template instantiations to be defined in multiple files, and the linker is required to only keep one of the definitions (This is the Borland model described at http://gcc.gnu.org/onlinedocs/gcc/Template-Instantiation.html). It is your job to ensure those definitions are the same. You can try the Gold linker's --detect-odr-violations option to get a warning about this kind of error.