cconstants

cconstants

Robbert Haarman

2013-08-11


Introduction

cconstants is a library and a set of command line utilities that allow the values of constants defined in C header files to be queried outside the C preprocessor. This allows the values of these constants to be queried from programming languages other than C, on systems without the C preprocessor installed, and on systems where the header files defining these constants are not available.


Examples

You can use cconstants in two ways: (1) as a library and (2) from the command line.

$ cconstants_get_long F_GETLK
5
$ cat example.c
#include <cconstants.h>
#include <stdbool.h>
#include <stdio.h>

int main(int argc, char **argv) {
  bool found;
  long value = cconstants_get_long("F_GETLK", &found);
  if (found) {
    printf("F_GETLK: %ld\n", value);
  } else {
    printf("F_GETLK not found");
  }
  return 0;
}
$ cc example.c -o example -lcconstants
$ ./example
F_GETLK: 5

Download

Cconstants is open source software under the terms of the GNU Lesser General Public License, version 2.1. The source code is hosted at SourceForge.

If you have the Git version control system installed, you can clone cconstants with the following command:


git clone git://git.code.sf.net/p/cconstants/code cconstants

Alternatively, you can obtain a ZIP file of the latest snapshot here: https://sourceforge.net/p/cconstants/code/ci/master/tarball


Installation

To build cconstants, you will need a C compiler, development header files, and make. Both GNU make and BSD make should work. Once you have those, building and installation should be as simple as:

$ ./configure
:
: output
:
$ make
:
: output
:
$ sudo make install
:
: output
:

This will install the library is /usr/local/lib and the binaries in /usr/local/bin. If different destinations are desired, these can be specified at installation time by overriding Makefile variables. For example, the following command installs binaries to /usr/bin and libraries to /usr/lib:

$ sudo make install PREFIX=/usr

See src/Makefile for the details of how installation works.

Valid XHTML 1.1! Valid CSS! Viewable with Any Browser