[Nice] Compilation of libnice code
Daniel Lobo
dlobo at student.dei.uc.pt
Fri Feb 15 08:27:14 PST 2013
This is not a question, but some kind of help for people with problems
compiling libnice examples. I was very surprised to find that no one
ever asked how to compile code using libnice, seeing as instructions
were impossible for me to find. Am I missing something really obvious?
Anyway, I have, for the past 4 days, been trying to compile and use a
C/C++ library that allows P2P communication for my project. After giving
up for now on the massively hard libjingle (hard to compile, hard to
understand, examples with thousands of lines...), I tried libnice.
Compiling the library (Windows and Linux):
I successfully compiled libnice under Windows, using VS (just follow the
readme given in the libnice package), and under Linux. If you are
compiling libnice in Linux, and are unexperienced like I am (the readme
instructions are nonexistent), know that you have to run (inside the
libnice folder) ./autogen.sh (run "chmod +x autogen.sh" if it gives
errors about permissions), ./configure, make, sudo make install, in this
order.
You *might* need to do some apt-gets before (glib-2.0?), but I can't
remember if that was true for me (I tried loooots of things when
attempting to build). If this is the case, I'm sorry that I can't help
enough, but I can't remember all that I did (besides, I believe you can
find most errors on the web, and they should direct you to some missing
library that can be acquired with apt-get).
Compiling examples:
After compiling, the thing was: I couldn't (and still can't) find
instructions on how to compile libnice examples, or what libraries and
paths to include. I tried to compile the example at
http://nice.freedesktop.org/libnice/NiceAgent.html (inside a main method
and using #include "agent.h") but I had to do a lot of trial and error
on code callbacks, linkage libraries, include paths, etc. Besides, there
was an undeclared variable "rcands" and, as of this writing, I still
haven't understood the theory about candidates.
I finally gave up after many many many undefined references of various
kinds.
The ONLY thing that did save me was something called pkg-config.
Apparently, pkg-config is a tool that knows what flags you have to use
when compiling and linking your code with some libraries. One of the
libraries which it can help is "nice" (libnice).
Eclipse:
If you are using Eclipse, like me, go to "Help -> Install New
Software...", use
http://petrituononen.com/pkg-config-support-for-eclipse-cdt/update as
the "Work with" site and select and install the plugin.
Then, on your project with the examples you want to run, go to
Properties -> C/C++ Build -> Pkg-config tab and select "nice". That
should set the correct includes, flags and libraries in the "Tool
Settings" tab. Now it's hopefully just a matter of using the right
#includes in your code.
For those without Eclipse and wanting to know the paths and libraries,
this is what pkg-config gave me in Linux:
GCC C/C++ Compiler -> Includes -> Include paths (-I):
/usr/include/glib-2.0
/usr/lib/x86_64-linux-gnu/glib-2.0/include
/usr/local/include/nice
Compiler (C or C++) -> Miscellaneous -> other flags:
-pthread
(in addition to -c -fmessage-length=0)
GCC C++ Linker -> Libraries -> Libraries (-l):
nice
gthread-2.0
rt
gio-2.0
gobject-2.0
glib-2.0
nice
gthread-2.0
rt
gio-2.0
gobject-2.0
glib-2.0
GCC C++ Linker -> Libraries -> Library search path:
/usr/local/lib
If it helps, Eclipse ended up doing something like:
Compiler:
g++ -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include
-I/usr/local/include/nice -O0 -g3 -Wall -c -fmessage-length=0 -pthread
-MMD -MP -MF"test.d" -MT"test.d" -o "test.o" "../test.cpp"
Linker:
g++ -L/usr/local/lib -o "libnice_tests" ./test.o -lnice -lgthread-2.0
-lrt -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lnice -lgthread-2.0 -lrt
-lgio-2.0 -lgobject-2.0 -lglib-2.0
pkg-config in Linux:
You can naturally also download and run pkg-config by itself (without
Eclipse) to get all of this, but I didn't do this so please bear with me
and search the web for a bit on the generic way to use pkg-config :) It
should be something like: gcc -o test test.c `pkg-config --libs --cflags
glib-2.0`
pkg-config in Windows:
Try to download pkg-config already pre-compiled from somewhere like:
http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/
The rest is the same as in Linux, but the problem is: pkg-config needs
some things set on path variables to detect the installed libraries and
I couldn't get it to work, not even in Eclipse :(
I hope some of this actually helps someone...
More information about the nice
mailing list