adobe / XMP-Toolkit-SDK

The XMP Toolkit allows you to integrate XMP functionality into your product or solution
BSD 3-Clause "New" or "Revised" License
205 stars 83 forks source link

Cannot link XMPCoreStatic.lib and XMPFilesStatic.lib together due to duplicate symbols. #93

Open Agendum opened 1 month ago

Agendum commented 1 month ago

Expected Behaviour

XMPCoreStatic.lib and XMPFilesStatic.lib can be linked into a single DLL.

Actual Behaviour

When attempting to link the following errors will be produced:

1>XMPCoreStatic.lib(CoreObjectFactoryImpl.obj) : error LNK2005: "public: static class AdobeXMPCore::ICoreObjectFactory_v1 * __cdecl AdobeXMPCore::ICoreObjectFactory_v1::GetCoreObjectFactory(void)" (?GetCoreObjectFactory@ICoreObjectFactory_v1@AdobeXMPCore@@SAPEAV12@XZ) already defined in XMPFilesStatic.lib(ICoreObjectFactory.obj)
1>XMPCoreStatic.lib(CoreObjectFactoryImpl.obj) : error LNK2005: "public: static void __cdecl AdobeXMPCore::ICoreObjectFactory_v1::SetupCoreObjectFactory(void)" (?SetupCoreObjectFactory@ICoreObjectFactory_v1@AdobeXMPCore@@SAXXZ) already defined in XMPFilesStatic.lib(ICoreObjectFactory.obj)
1>XMPCoreStatic.lib(CoreObjectFactoryImpl.obj) : error LNK2005: "public: static void __cdecl AdobeXMPCore::ICoreObjectFactory_v1::DestroyCoreObjectFactory(void)" (?DestroyCoreObjectFactory@ICoreObjectFactory_v1@AdobeXMPCore@@SAXXZ) already defined in XMPFilesStatic.lib(ICoreObjectFactory.obj)

Reproduce Scenario (including but not limited to)

When creating static libraries XMPCoreStatic.lib and XMPFilesStatic.lib, and then attempting to build them into a single module (i.e. a DLL), you will get the above build failures. This is because both static libraries build three identical symbols:

AdobeXMPCore::ICoreObjectFactory_v1::GetCoreObjectFactory AdobeXMPCore::ICoreObjectFactory_v1::SetupCoreObjectFactory AdobeXMPCore::ICoreObjectFactory_v1::DestroyCoreObjectFactory

Here is where XMPCoreStatic.lib generates its version of these symbols.

Here is where XMPFilesStatic.lib generates its version of these symbols.

Steps to Reproduce

  1. Build both libraries with default settings (for windows_x64).
  2. Link both libraries into a single DLL.

Platform and Version

Windows x64, using the latest sources targeting 2023-12.

Sample Code that illustrates the problem

N/A

Logs taken while reproducing problem

See behavior steps above.

For anybody else experiencing this, you can work-around the issue by specifying /FORCE:MULTIPLE on the linker command line. You will still see the error in the output, but at least it builds.