Hi xp,
your build failure is
- 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:
- 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)
- a “library“ .LIB is a collection of one or more of such .OBJ files
- 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
- 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
- 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
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