• Stars
    star
    363
  • Rank 117,374 (Top 3 %)
  • Language
    C
  • License
    BSD 3-Clause "New...
  • Created over 13 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A simple, easily embeddable cross-platform C library

libcork

Build Status

So what is libcork, exactly? It's a “simple, easily embeddable, cross-platform C library”. It falls roughly into the same category as glib or APR in the C world; the STL, POCO, or QtCore in the C++ world; or the standard libraries of any decent dynamic language.

So if libcork has all of these comparables, why a new library? Well, none of the C++ options are really applicable here. And none of the C options work, because one of the main goals is to have the library be highly modular, and useful in resource-constrained systems. Once we describe some of the design decisions that we've made in libcork, you'll hopefully see how this fits into an interesting niche of its own.

Using libcork

There are two primary ways to use libcork in your own software project: as a shared library, or embedded.

When you use libcork as a shared library, you install it just like you would any other C library. We happen to use CMake as our build system, so you follow the usual CMake recipe to install the library. (See the INSTALL file for details.) All of the libcork code is contained within a single shared library (called libcork.so, libcork.dylib, or cork.dll, depending on the system). We also install a pkg-config file that makes it easy to add the appropriate compiler flags in your own build scripts. So, you use pkg-config to find libcork's include and library files, link with libcork, and you're good to go.

The alternative is to embed libcork into your own software project's directory structure. In this case, your build scripts compile the libcork source along with the rest of your code. This has some advantages for resource-constrained systems, since (assuming your compiler and linker are any good), you only include the libcork routines that you actually use. And if your toolchain supports link-time optimization, the libcork routines can be optimized into the rest of your code.

Which should you use? That's really up to you. Linking against the shared library adds a runtime dependency, but gives you the usual benefits of shared libraries: the library in memory is shared across each program that uses it; you can install a single bug-fix update and all libcork programs automatically take advantage of the new release; etc. The embedding option is great if you really need to make your library as small as possible, or if you don't want to add that runtime dependency.

Design decisions

Note that having libcork be easily embeddable has some ramifications on the library's design. In particular, we don't want to make any assumptions about which build system you're embedding libcork into. We happen to use CMake, but you might be using autotools, waf, scons, or any number of others. Most cross-platform libraries follow the autotools model of performing some checks at compile time (maybe during a separate “configure” phase, maybe not) to choose the right API implementation for the current platform. Since we can't assume a build system, we have to take a different approach, and do as many checks as we can using the C preprocessor. Any check that we can't make in the preprocessor has to be driven by a C preprocessor macro definition, which you (the libcork user) are responsible for checking for and defining. So we need to have as few of those as possible.

More Repositories

1

expression-problem-rust

Exploring the "expression problem" in Rust
Rust
46
star
2

libpush

An arrow-based parser combinator library for C
C
40
star
3

graffle-export

Command-line utility for exporting OmniGraffle documents
Shell
25
star
4

varon-t

C implementation of Disruptor queues
C
22
star
5

dotfiles

GitHub Codespaces setup
Shell
14
star
6

libcorkipset

A small C helper library for storing sets of IPv4 and IPv6 addresses
C
10
star
7

dotfiles-base

Simple shell-based dotfiles manager
Shell
8
star
8

jemalloc

Clone of the standalone jemalloc library
C
6
star
9

dotfiles-public

Public dotfiles
Ruby
6
star
10

avro-examples

A handful of documented examples of using the Avro C API
C
6
star
11

cudd

Colorado University Decision Diagram package
C
5
star
12

cabal

Haskell Cabal build system
Haskell
4
star
13

cppcsp2

Clone of Kent C++CSP2 project
4
star
14

libhwm

A C library for “high-water mark” buffers
C
4
star
15

jpwsafe

Git mirror of jpwsafe: Java clone of PasswordSafe
4
star
16

bowsprit

Statistics counters in C
C
4
star
17

buzzy

OS-agnostic package builder
C
4
star
18

clogger

A C logging library based on Python's logbook
C
4
star
19

presentations

Presentations that I've given
TeX
3
star
20

csp-models

FDR via Docker and various interesting CSP models
Shell
3
star
21

clj-bdd

Binary decision diagrams in Clojure
Clojure
3
star
22

home

My home directory
Emacs Lisp
2
star
23

croissant

Pastry peer-to-peer overlay network, in C
C
2
star
24

fleet

Lightweight concurrency and parallelism library
C
2
star
25

revelation

Git mirror of the Revelation GNOME password manager
2
star
26

controlled-option

Custom Option type with explicit control over niches and memory layout
Rust
1
star
27

waf-test

Test cases for waf bugs that I discover
C
1
star
28

luajit

Fork of LuaJIT for patch submissions
C
1
star
29

ports

A local MacPorts repository
1
star
30

kateanddoug.com

Wedding website
Ruby
1
star
31

mlua-tree-sitter

Adds `ltreesitter` Lua bindings to `mlua`-managed Lua environments
Rust
1
star
32

stuffed-records-go

Stuffed Records in Go
Go
1
star
33

dcreager.net

The source for dcreager.net
HTML
1
star
34

virtualenv

Clone of the virtualenv project
Python
1
star
35

recipes

Some recipes that I like
1
star