CMP0156.rst 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. CMP0156
  2. -------
  3. .. versionadded:: 3.29
  4. De-duplicate libraries on link lines based on linker capabilities.
  5. Traditional linkers maintain a set of undefined symbols during linking. The
  6. linker processes each file in the order in which it appears on the command
  7. line, until the set of undefined symbols becomes empty. An object file is
  8. linked into the output object when it is encountered, with its undefined
  9. symbols added to the set. Upon encountering an archive file a traditional
  10. linker searches the objects contained therein, and processes those that satisfy
  11. symbols in the unresolved set.
  12. Handling mutually dependent archives may be awkward when using a traditional
  13. linker. Archive files may have to be specified multiple times.
  14. Some linkers (for instance Apple or Windows linkers, as well as ``LLVM LLD``)
  15. record all symbols found in objects and archives as they iterate over command
  16. line arguments. When one of these linkers encounters an undefined symbol that
  17. can be resolved by an object file contained in a previously processed archive
  18. file, it immediately extracts and links it into the output object.
  19. CMake 3.28 and below may generate link lines that repeat static libraries as
  20. a traditional linker would need, even when using a linker that does not need it.
  21. They may also de-duplicate shared libraries by keeping their last occurrence,
  22. which on Windows platforms can change DLL load order.
  23. CMake 3.29 and above prefer to apply different strategies based on linker
  24. capabilities. So, when targeting Apple and Windows platforms, all
  25. libraries are de-duplicated. Moreover, on Windows platforms, libraries
  26. are de-duplicated by keeping their first occurrence, thus respecting the
  27. project-specified order. This policy provides compatibility with projects
  28. that have not been updated to expect the latter behavior.
  29. The ``OLD`` behavior for this policy is to always repeat static libraries
  30. as if using a traditional linker, and always de-duplicate shared libraries
  31. by keeping the last occurrence of each. The ``NEW`` behavior for this policy
  32. is to apply different strategies based on linker capabilities.
  33. .. |INTRODUCED_IN_CMAKE_VERSION| replace:: 3.29
  34. .. |WARNS_OR_DOES_NOT_WARN| replace:: does *not* warn
  35. .. include:: STANDARD_ADVICE.txt
  36. .. include:: DEPRECATED.txt