Hi xp,

your build failure is

  1.  the result of a “link-all” mechanism

or
       2. the result of a library construction flaw that is commonly used in 
EDK2.

or both

Let me explain the theory:


  1.  an .OBJ file is created by the compiler for each .C source code file

an .OBJ is considered as atomic, it can not be split into smaller pieces 
(except with newer compiler switches)

  1.  a “library“ .LIB is a collection of one or more of such .OBJ files
  2.  if an .OBJ is passed to linker, it is _always_ linked into the target.EFI

(the linker creates an link-error, like yours, if that particular symbol-name 
is already present in the target.EFI)

One definition rule: 
https://docs.microsoft.com/en-us/cpp/error-messages/tool-errors/linker-tools-error-lnk2005?view=msvc-170

  1.  if an .LIB is passed to the linker instead, the linker searches the .LIB 
for a particular

symbol (e.g. function, data). The specific .OBJ module that holds that 
particular symbol, is

linked to the target.EFI.

(the linker creates an link-error, like yours, if that particular symbol-name 
is already present in the target.EFI)

One definition rule: 
https://docs.microsoft.com/en-us/cpp/error-messages/tool-errors/linker-tools-error-lnk2005?view=msvc-170

  1.  to prevent such error each .OBJ of a library can hold only one single 
symbol, one function or one data.

Only in that case the linker is able to pickup each single symbol from the 
library and bind it into the target.EFI

without any conflict.


This is also explained here:
https://github.com/tianocore/edk2-staging/tree/CdePkg/blogs/2021-12-19#redfishcrtlib-conflicts-with-cdepkg-by-design

Best regards,
Kilian

________________________________
From: devel@edk2.groups.io <devel@edk2.groups.io> on behalf of M.T. 
<xzavierpo...@gmail.com>
Sent: Wednesday, May 25, 2022 6:23:02 PM
To: devel@edk2.groups.io <devel@edk2.groups.io>
Subject: [edk2-devel] including redfish libs results in multiple definitions of 
symbols

Hello

I'm working on a small UEFI shell app.
I was hoping to make use of the JsonLib found in the Redfish Package.

When I include the Redfish JsonLib and it's dependencies:
JsonLib|RedfishPkg/Library/JsonLib/JsonLib.inf
Ucs2Utf8Lib|RedfishPkg/Library/BaseUcs2Utf8Lib/BaseUcs2Utf8Lib.inf
RedfishCrtLib|RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.inf
BaseSortLib|MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf

BaseSortLib has symbol clashes with SortLib resulting in the following:

/usr/bin/ld: UefiSortLib.obj (symbol from plugin): in function 
`PerformQuickSort':
(.text+0x0): multiple definition of `PerformQuickSort'; BaseSortLib.obj (symbol 
from plugin):(.text+0x0): first defined here
/usr/bin/ld: UefiSortLib.obj (symbol from plugin): in function 
`PerformQuickSort':
(.text+0x0): multiple definition of `DevicePathCompare'; BaseSortLib.obj 
(symbol from plugin):(.text+0x0): first defined here
/usr/bin/ld: UefiSortLib.obj (symbol from plugin): in function 
`PerformQuickSort':
(.text+0x0): multiple definition of `StringNoCaseCompare'; BaseSortLib.obj 
(symbol from plugin):(.text+0x0): first defined here
/usr/bin/ld: UefiSortLib.obj (symbol from plugin): in function 
`PerformQuickSort':
(.text+0x0): multiple definition of `StringCompare'; BaseSortLib.obj (symbol 
from plugin):(.text+0x0): first defined here

I need SortLib for UEFIShell dependencies, and I need BaseSortLib for JsonLib.
Is there some way around this?  Or is Redfish meant to be standalone?

Thank you in advance
xp



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#90013): https://edk2.groups.io/g/devel/message/90013
Mute This Topic: https://groups.io/mt/91336682/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to