How to fix duplicate exported symbols in GCC-created DLL

-2

I am building a DLL using GCC (g++) but it contains multiple references to the same exported symbol, all but one having an address of zero. How can I eliminate these rogue duplicates?

I have tried using the default 'export-all-symbols' mode, specifying which symbols I want to be exported using __declspec(dllexport), and using a .def file. None fixes the problem: either the symbol isn't exported at all or it is exported multiple times.

This is a filtered extract from an 'objdump' of the created DLL; ordinal [721] is the wanted export, with address 2f6e4, the others are seemingly spurious:

[721](sec  1)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x0002f6e4 __ZNK6b2Body7GetTypeEv
[1211](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 __ZNK6b2Body7GetTypeEv
[1344](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 __ZNK6b2Body7GetTypeEv
[1499](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 __ZNK6b2Body7GetTypeEv
[1601](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 __ZNK6b2Body7GetTypeEv
[1726](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 __ZNK6b2Body7GetTypeEv
[2323](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 __ZNK6b2Body7GetTypeEv
[2447](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 __ZNK6b2Body7GetTypeEv
[2552](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 __ZNK6b2Body7GetTypeEv
[2661](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 __ZNK6b2Body7GetTypeEv
[2765](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 __ZNK6b2Body7GetTypeEv
[2877](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 __ZNK6b2Body7GetTypeEv
[2992](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 __ZNK6b2Body7GetTypeEv
[3110](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 __ZNK6b2Body7GetTypeEv
[3226](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 __ZNK6b2Body7GetTypeEv
[3344](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 __ZNK6b2Body7GetTypeEv
[3451](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 __ZNK6b2Body7GetTypeEv
[3556](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 __ZNK6b2Body7GetTypeEv
c++
gcc
dll
asked on Stack Overflow Jul 30, 2019 by user1912647

1 Answer

0

https://demangler.com/ tells me that you have _b2Body::GetType() const defined in more than one translation unit. This is (probably) either because you have defined this symbol in a header file or you have defined it in a .cpp file which you have #included more than once elsewhere.

So, fix that and your problem should go away.

Also, identifiers starting with an underscore in the global namespace are reserved for library implementers, so you might like to fix that too.

answered on Stack Overflow Jul 30, 2019 by Paul Sanders • edited Jul 30, 2019 by Paul Sanders

User contributions licensed under CC BY-SA 3.0