Live data from Hacker News

Single-file public-domain/open source C libraries with minimal dependencies

github.com

1–10 of 51 posts

Re: Single-file public-domain/open source C libraries with minimal dependencies

#4

Why isn't SQLite's amalgamated build on this list? Come on. I don't understand this. Can someone explain it to me?

> The amalgamation is a single C code file, named "sqlite3.c", that contains all C code for the core SQLite library and the FTS3, FTS5, RTREE, DBSTAT, JSON1, and RBU extensions. This file contains about 184K lines of code (113K if you omit blank lines and comments) and is over 6.4 megabytes in size. Though the the various extensions are included in the "sqlite3.c" amalgamation file, they are disabled using #ifdef statements.

https://www.sqlite.org/amalgamation.html

Re: Single-file public-domain/open source C libraries with minimal dependencies

#5
http://git.annexia.org/?p=miniexpect.git

It's an "expect"-like library written in C (and more sane than the Tcl original). It's 3 files, because it has a header file and a manual page.

It's just 390 lines of code because it's implemented using some PCRE trickery.

Re: Single-file public-domain/open source C libraries with minimal dependencies

#6
Uh, this stb library [1] seems to follow a horrible pattern: not only combining your code into a single .c file (which is fine, like the sqlite amalgamation), but putting the code into a single .h file. [2]

I've never seen a C or C++ codebase that does this. Maybe you can rely on link-time deduplication, but it will still cause duplicate compilation, and thus increased compile times. I haven't thought it about it lately, but I thought the common wisdom was not to depend on the linker to dedupe or strip unused symbols. Actually it should cause link-time errors, not just duplicated cause.

The justification is also somewhat ridiculous: Why single-file headers?

Windows doesn't have standard directories where libraries live. That makes deploying libraries in Windows a lot more painful than open source developers on Unix-derivates generally realize. (It also makes library dependencies a lot worse in Windows.)

Really? Why not just lay out your source normally, and then munge it with a simple script into something Windows can handle (similar to sqlite)? Because writing trivial scripts on Windows is also a pain?

[1] https://github.com/nothings/stb

[2] https://github.com/nothings/stb/blob/master/stb_c_lexer.h

Re: Single-file public-domain/open source C libraries with minimal dependencies

#9
post #6

Uh, this stb library [1] seems to follow a horrible pattern: not only combining your code into a single .c file (which is fine, like the sqlite amalgamation), but putting the code into a single .h file. [2] I've never seen a C or C++ codebase that does this. Maybe you can rely on link-time deduplication, but it will still cause duplicate compilation, and thus increased compile times. I haven't thought it about it lat…

Note that the implementation code is conditionally compiled. By default you only compile the headers, so it's up to you instantiate the implementation somewhere by setting a preprocessor symbol before you include the library. This is described in the comment at the top of the file.

Re: Single-file public-domain/open source C libraries with minimal dependencies

#10
Here are some more...

Kazlib contains a few single-file (actually one .c file and one .h file) open source C libraries. For example, there's a dictionary data structure based on red-black trees, dict.c/dict.h, which I've found to be useful and reliable. There's also a linked list library, a hash table library, etc., but I haven't used these.

Home page: http://www.kylheku.com/~kaz/kazlib.html

Source code: http://git.savannah.gnu.org/cgit/kazlib.git/tree/

The latest version uses the BSD License.

Post reply on HN