I've just started working with CMake and I noticed that they have both a find_package
and a find_library
. And this confuses me. Can somebody explain the difference between a package and a library in the world of programming? Or, in the world of CMake?
Appreciate it, guys!
However, it is often assumed that while a package is a collection of modules, a library is a collection of packages. Oftentimes, developers create Python libraries to share reusable code with the community.
Package is a collection of modules. It must contain an __init__.py file as a flag so that the python interpreter processes it as such. The __init__.py could be an empty file without causing issues. Library is a collection of packages.
Packages are collections of R functions, data, and compiled code in a well-defined format, created to add specific functionality. There are 10,000+ user contributed packages and growing.
Also, a library is a collection of related functionality, whereas a module only provides a single piece of functionality. Which means that, if you have a system with both modules and libraries, a library will typically contain multiple modules.
Imagine you want to use zlib in your project, you need to find the header file zlib.h
, and the library libz.so
(on Linux). You can use the low-level cmake commands find_path
and find_library
to find them, or you can use find_package(ZLIB)
. The later command will try to find out all what is necessary to use zlib. It can be extra macro definitions, or dependencies.
Update, more detail about find_package
: when the CMake command find_package(SomeThing)
is called, as in the documentation, there are two possible modes that cmake can run:
FindSomeThing.cmake
)SomeThingConfig.cmake
)For ZLIB, there is a module named FindZLIB
, shipped with CMake itself (on my Linux machine that is the file /usr/share/cmake/Modules/FindZLIB.cmake
). That module is a CMake script that uses the CMake API to search for ZLIB files in default locations, or ask the user for the location if it cannot be found automatically.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With