You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
3.4 KiB

  1. # libcork
  2. So what is libcork, exactly? It's a “simple, easily embeddable,
  3. cross-platform C library”. It falls roughly into the same category as
  4. [glib](http://library.gnome.org/devel/glib/) or
  5. [APR](http://apr.apache.org/) in the C world; the STL,
  6. [POCO](http://pocoproject.org/), or [QtCore](http://qt.nokia.com/)
  7. in the C++ world; or the standard libraries of any decent dynamic
  8. language.
  9. So if libcork has all of these comparables, why a new library? Well,
  10. none of the C++ options are really applicable here. And none of the C
  11. options work, because one of the main goals is to have the library be
  12. highly modular, and useful in resource-constrained systems. Once we
  13. describe some of the design decisions that we've made in libcork, you'll
  14. hopefully see how this fits into an interesting niche of its own.
  15. ## Using libcork
  16. There are two primary ways to use libcork in your own software project:
  17. as a _shared library_, or _embedded_.
  18. When you use libcork as a shared library, you install it just like you
  19. would any other C library. We happen to use CMake as our build system,
  20. so you follow the usual CMake recipe to install the library. (See the
  21. [INSTALL](INSTALL) file for details.) All of the libcork code is
  22. contained within a single shared library (called libcork.so,
  23. libcork.dylib, or cork.dll, depending on the system). We also install a
  24. pkg-config file that makes it easy to add the appropriate compiler flags
  25. in your own build scripts. So, you use pkg-config to find libcork's
  26. include and library files, link with libcork, and you're good to go.
  27. The alternative is to embed libcork into your own software project's
  28. directory structure. In this case, your build scripts compile the
  29. libcork source along with the rest of your code. This has some
  30. advantages for resource-constrained systems, since (assuming your
  31. compiler and linker are any good), you only include the libcork routines
  32. that you actually use. And if your toolchain supports link-time
  33. optimization, the libcork routines can be optimized into the rest of
  34. your code.
  35. Which should you use? That's really up to you. Linking against the
  36. shared library adds a runtime dependency, but gives you the usual
  37. benefits of shared libraries: the library in memory is shared across
  38. each program that uses it; you can install a single bug-fix update and
  39. all libcork programs automatically take advantage of the new release;
  40. etc. The embedding option is great if you really need to make your
  41. library as small as possible, or if you don't want to add that runtime
  42. dependency.
  43. ## Design decisions
  44. Note that having libcork be **easily** embeddable has some ramifications
  45. on the library's design. In particular, we don't want to make any
  46. assumptions about which build system you're embedding libcork into. We
  47. happen to use CMake, but you might be using autotools, waf, scons, or
  48. any number of others. Most cross-platform libraries follow the
  49. autotools model of performing some checks at compile time (maybe during
  50. a separate “configure” phase, maybe not) to choose the right API
  51. implementation for the current platform. Since we can't assume a build
  52. system, we have to take a different approach, and do as many checks as
  53. we can using the C preprocessor. Any check that we can't make in the
  54. preprocessor has to be driven by a C preprocessor macro definition,
  55. which you (the libcork user) are responsible for checking for and
  56. defining. So we need to have as few of those as possible.