« UK counties, php array | Main | M17: the Omega Nebula »

C/C++ libraries

Its been ages since I did any proper C/C++ so I had to remind myself of a few things, particularly the compilation of libraries. Libraries are really useful as it simplifies multiple use and sharing of components. I'm a Linux person so I'm going to look at this with a Linux hat on. In Linux there are two types; Static libraries (.a) and dynamically linked shared object libraries (.so). Let take a look at static libraries.

Lets create a library, firstly lets define some code, say in a file example1.c:

To create a library you can do:

cc -c example1.c

which compiles the code. Then you need to make the libary:

ar -cvq libexample.a example1.o

(you can of course include other object files here)

Say you call the function in you maincode.c to now compile this do:

cc -o maincode maincode.c libexample.a


TrackBack

TrackBack URL for this entry:
http://krioma.net/cgi-bin/MT-3.38/mt-tb.cgi/573

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About

This page contains a single entry from the blog posted on December 1, 2011 9:06 PM.

The previous post in this blog was UK counties, php array.

The next post in this blog is M17: the Omega Nebula.

Many more can be found on the main index page or by looking through the archives.

Get Firefox! Valid XHTML 1.0! Valid CSS! RSS Feed BlogUniverse - listed Powered by Apache Creative Commons License ringsofsaturnrock's Most Interesting Photos on Flickriver

Powered by
Movable Type 3.38