Hunting for a Library

To add more functionality to the C language, you mix in another library. The library contains routines (functions) that let you control specific hardware, manipulate data, work with graphics, and a host of other capabilities beyond the standard C library.

The first step to adding a library is to figure out what you need the program to do. For example, if you want to program the terminal (text) window on a Mac or Linux computer, you could obtain the NCurses library. NCurses is very interesting and fun to code, and I may explore it in the future on this blog. For now, consider that you want a library to read XML data.

XML is the eXtensible Markup Language, essentially a text file but one with consistent elements and help organize information. A web page, or HTML document, is a type of XML file.

Sure, you could code your own routines that parse and process XML formatted data. If you were after a quick-and-dirty tidbit of information, that trick works (and I’ve done it before). But for more control, it’s best to use an XML library. Otherwise you’re just reinventing the wheel (which happens frequently in programming).

The two items you need to obtain are the XML library itself and its companion header file(s). Further, you need the version of the library that’s compatible with the computer’s operating system and possibly the compiler as well.

For an XML library, I visited The XML C parser and toolkit of Gnome website. The Downloads link on the home page lists options to obtain the “binaries” or libraries you need for various operating systems platforms.

As is the case with many developer tools, the binaries are probably archived and do not include an installer. This decision was made deliberately as it allows you more control; you can move or copy the files to a preferred location.

After downloading the Windows 10 64-bit binaries, I copied the libraries into MinGW’s lib folder for use in Code::Blocks. The header files I copied into the include folder.

The Mac comes with an XML library preinstalled. Still, if you’re after C libraries on the Mac, I recommend using the Homebrew system to obtain them.

In Linux you can download the XML library from the xlmsoft.org website, or you can use the distro’s package management tool to obtain and install new libraries.

Once you’ve obtained and installed the libraries and headers, you can begin using the library’s functions in your programs. Don’t expect this step be easy or fast! Each library takes getting used to. The website may offer sample code plus a documentation for the API (Application Programming Interface). Give yourself time to learn it.

Leave a Reply