27

Are there any good configuration file reading libraries for C\C++ that can be used for applications written on the linux platform. I would like to have a simple configuration file for my application. At best i would like to steer clear of XML files that might potentially confuse users.

jcodeninja
  • 2,155
  • 4
  • 17
  • 14
  • 2
    I think your decision to avoid XML is a good one. XML isn't really human readable except in an emergency. – Mark Baker Sep 29 '08 at 08:39

7 Answers7

25

I would recommend 'libconfig'.

ayaz
  • 10,406
  • 6
  • 33
  • 48
11

You could try glib's key-value-file-parser

Chris Young
  • 15,627
  • 7
  • 36
  • 42
8

Another option is Boost.PropertyTree (doc). It allows to read/write XML, INI, JSON and Info files. And you get portability for free.

jk.
  • 6,388
  • 2
  • 26
  • 21
6

Boost program_options This allows you to read program options from config files, environment variables and the command line. It is portable and very easy to use.

Ben James
  • 121,135
  • 26
  • 193
  • 155
1800 INFORMATION
  • 131,367
  • 29
  • 160
  • 239
1

For a single app, you could consider libconfuse.

If you need to be able to handle a wide variety of config file formats (e.g. for a web portal for a system, which needs to read and write config files from many apps in many formats), there is Augeas.

Craig McQueen
  • 41,871
  • 30
  • 130
  • 181
1

If you just want a simple config file, with a list of commands and/or variable settings, then it's very easy to write your own parser, so easy that it's probably not worth using a library. If you need something more complicated then the parser rapidly becomes more complicated and an existing library is worth using.

I've never tried using libconfig, but it looks like a good choice, and I like the format of the config files it uses.

You need to decide whether you want your program to be able to write config files. If it's a GUI program, you probably do. This will affect what libraries are suitable.

Mark Baker
  • 5,588
  • 2
  • 27
  • 25
0

The question is what file format did you have in mind? The attribute "simple" is a bit of an underspecification. If you are looking for a library that can use "windows .ini formated" config files you may want to check out ACE http://www.cs.wustl.edu/~schmidt/ACE/ .

lothar
  • 19,853
  • 5
  • 45
  • 59