loading...

CLibs: A Package Manager for C

noah11012 profile image Noah11012 ・1 min read

Many modern-day languages like Python and Rust have their own standard package managers that help with installing dependencies for projects. C never had one... until now.

CLibs is a package manager for C that is focused on "micro" libraries. This means all libraries you can install with CLibs are lightweight, fast, and have a small footprint in your overall projects.

Getting Started

To install CLibs, enter in the following commands into your preferred terminal:

git clone https://github.com/clibs/clib.git /tmp/clib
cd /tmp/clib
make
sudo make install

Make sure you have the developer version of libcurl installed on your system.

Searching for the package you need is easy.

clib search [package-name]

Installing is also easy.

clib install <user>/<repo>

You can install more than one package at a time.

Integrating with CLibs

Maybe you're convinced that CLibs is the package manager for C and you would like to get your project to become supported by CLibs.

The way CLibs was created in mind, this is extremely simple to do. Create a package.json file at the root directory of your project. A template would like something like the following:

{
  "name": "term",
  "version": "0.0.1",
  "repo": "clibs/term",
  "description": "Terminal ansi escape goodies",
  "keywords": ["terminal", "term", "tty", "ansi", "escape", "colors", "console"],
  "license": "MIT",
  "src": ["src/term.c", "src/term.h"]
}

For more details on package.json: https://github.com/clibs/clib/wiki/Explanation-of-package.json

Now that you know a package manager exists for C, will you add support for CLibs?

Github repository for CLibs: https://github.com/clibs/clib

Posted on by:

Discussion

markdown guide
 

Not to be mean or harsh, but can’t one just use a regular package manager?

 

I'm not sure what you mean by a "regular" package manager. If you mean the package manager provided by a Linux distribution like Linux Mint or Manjaro, then yes, you can use that if you prefer.

However, creating packages that are Debian based (not sure how to create packages for Manjaro) takes a lot more work than simply adding a package.json file to your project. It's similar to spirit to using npm when creating/working on JS projects.

 

Yes, it's a bit harder to package for Debian, but it's a one-time job, and you don't have to edit anything related to the packaging pipeline to add or remove files, as it's completely independent of one's build tools.

That is true, but CLibs is focused on small C libraries; typically no more than a few files. So, adding/removing files from the package.json is not a frequent issue.

If your library is much bigger than a few files, that I would recommend going with a regular package manager.

But then what’s the advantage with small libraries?

Small libraries are lightweight because of their small footprint. You're only using what you need and not having it coupled with a framework or part of a bigger library.

Of course, bigger libraries have their place in the world of programming, but sometimes one just needs a micro library to do the job.

No, I meant what advantage does one get by having people install one’s package through CLibs?

A couple of reasons: the creator of CLibs states that libraries for C are scattered all over the web and CLibs can help them discover these types of libraries for themselves.

CLibs isn't required to be installed for the end users or contributors. This allows CLibs to seamlessly integrate with any new or existing projects.

And how does it help people discover libraries any more than a simple Google search?

Again, CLibs helps to discover micro-libraries.

You didn’t answer my question.

The author the library expressed the sentiment that the discovery of C libraries is "relatively poor" and sometimes they are unfocused and have a bigger than necessary footprint.

The point of CLibs is to use micro-libraries that meet your project's needs. Yes, a simple Google search might suffice for a bigger project, but for the search of smaller libraries, it might not.

Personally, I don't use CLibs, mainly because I only have one project in C. The reason I made this post is so that other people would know about and perhaps some of them would find a use for it.

Still, what does it do to make discovery easier?

Just by using clib search [package-name]. Sure, you could Google search it, but, it might not come up.

But you still need to know about the library to do that, so it’s more of a “Can I install this through CLibs?” thing.

Sure. If you want to, Google can be a great place to find certain libraries and for others, it might not be.

There's nothing wrong with wanting to use Google for this purpose, it's just that CLibs can offer another channel for finding useful libraries.

Now you’re basically just repeating yourself.

Sorry, but that's all I have to say in this discussion. Use Google if you want and CLibs for an extra avenue for finding libraries.