libircpp manual

  1. Introduction
  2. Hello World
  3. Compiling and installing
  4. Signals
  5. Example: op-me bot
  6. Messages
  7. Users and Channels
  8. User and Channel Lists
  9. Example: Channel Logger
  10. Planned features

3. Compiling and installing

Now we've seen how libircpp works, the next thing is to try compiling and running our Hello World program. Because libircpp is a library, we need to link it to any program we want to use it - in this case Hello World. Oh, and libircpp needs one other library to work (only one, I promise!). It's called Boost Signals, and I'll explain why it's needed in the next chapter. So, the first step is to install Boost Signals.

Step 1: Installing boost signals

If you have a package-management system, this is probably the easiest way to install boost signals. On debian and ubuntu, you would type (as root):
apt-get install libboost-signals libboost-signals-dev
If that works, you can skip to step 2. You may find that you need to install the whole of the Boost package, depending on how your distribution has it packaged. If you don't have a package manager, you can always compile it from source:

Download boost, following the instructions here, under "Get Boost":

http://www.boost.org/more/getting_started/unix-variants.html
You should get a file like boost_1_34_1.tar.bz2 - install it like this (as root):
tar jxf boost_1_34_1.tar.bz2
cd boost_1_34_1
./configure --prefix=/usr
make
make install

Step 2: Installing libircpp

Now we can install libircpp itself. Download it from libircpp.sf.net. You should get a file like libircpp-0.1.tar.gz (the version may be newer). Install it like this (as root):
tar zxf libircpp-0.1.tar.gz
cd libircpp-0.1 
./configure --prefix=/usr
make
make install

Step 3: Compiling Hello World

You can find helloworld.cpp in the test/ subdirectory of the libircpp source package. Compile it with the following command:
gcc -o helloworld -lircpp -lboost_signals helloworld.cpp
This will compile helloworld.cpp into an executable "helloworld". The -lircpp and -lboost_signals options tell the compiler to link with the two libraries: libircpp, and boost_signals.

Run it by typing ./helloworld - you should be able to see it join the channel you specified in helloworld.cpp, and say hello, like this:

libircpp (~libircpp@1.2.3.4) has joined #mychannel
<libircpp> Hello world!
When you're done, press Ctrl-C to kill it.

Static compilation

So far, we have compiled Hello World dynamically. This means that when it is run, it will look for, and use, the libraries that are installed on the system where it is running. This is easy, and produces a smaller executable file, but it has the disadvantage that the executable will not run on a system where the libraries aren't installed, or where they are out of date.

Compiling statically means that the libraries are built into the executable. This means that the executable is larger, but will run anywhere - it is "standalone". To compile statically, do:

g++ -o helloworld helloworld.cpp /usr/lib/libircpp.a /usr/lib/libboost_signals.a
(Change the paths to the libraries if you have installed them somewhere other than /usr/lib). Compiling statically also provides a way of compiling if you do not have root access to install the libraries. You can compile both Boost Signals and libircpp, and copy the respective .a files into your working directory (you can find libircpp.a in libircpp/.libs/ and the libboost_signals.a in a similar place in the boost compilation directory). Then just include them in your build as if they were source files:
g++ -o helloworld helloworld.cpp libircpp.a libboost_signals.a
Next: Signals