0

MyExe, links to StaticLib1 and StaticLib2. Both static libs compile SomeFile.cpp

Is that a problem? Given that these are static libs? (In DLL world, at least on windows, they are NOT a problem).

Is there an ODR violation? I am confused: one part of me says two copies == problem. The other part says the linker is smart enough to silently discard duplicate copies, and as long as compilation was "same" == no problem. The third part whispers "beware of that silent discard"

If there are problems, then, any remedies short of "tell StaticLib1 and StaticLib2 to NOT compile SomeFile.cpp; compile it separately as part of Exe or as part of a separate lib".

What is SomeFile.cpp in StaticLib1 was coming from zlib version 1.0 and in StaticLib2 was coming from zlib version 2.0? More mayhem? The indeed linker silently discarding one set of symbols and picking up others might be problem.

Amit
  • 1,836
  • 15
  • 24
  • give compiler and linker name, version , build etc. – M.M Aug 07 '21 at 02:38
  • I need the solution to work across OS and compilers; so Visual Studio 2019, XCode12, Android Studio 4 MS cc compiler; clang, llvm, gcc: all of them We are open to putting together compiler specific solutions – Amit Aug 07 '21 at 02:40
  • ODR applies to individual symbols, rather than entire translation units. This cannot be authortitatively answered without concrete, specific details. – Sam Varshavchik Aug 07 '21 at 02:42
  • ok. SomeFile.cpp has this function void CompressStream(void* stream); A simple file. Consider it one of the files in zlib. – Amit Aug 07 '21 at 02:44
  • possible dupe: https://stackoverflow.com/questions/29079742/same-symbols-in-different-libraries-and-linking-order – NathanOliver Aug 07 '21 at 02:45
  • The standard cannot tell you whether you have a problem, because the standard doesn't know which translation units are included in the program when libraries are present, because the standard doesn't know libraries (except for the standard library). So you need to ask the linker which objects (== compiled translation units) are included in the program. The linker will tell you that it includes objects from the static library that are needed to resolve symbols, and does not include objects that are not needed to resolve symbols, and when a (single) object is included, the symbol is resolved. – n. m. could be an AI Aug 07 '21 at 06:57

0 Answers0