[Nice] Compilation of libnice code

Youness Alaoui youness.alaoui at collabora.co.uk
Fri Feb 15 15:37:40 PST 2013


Hey again Daniel!

My colleague Olivier just told me that there actually are build instructions
with libnice, I didn't even notice! :p
The INSTALL file is actually auto generated (gets updated by the system when you
run ./autogen.sh) and gives you the build instructions and everything you need
to know about how to build libnice or any such similar software.
It does not mention pkg-config though, but it gives you enough info to know how
to ./configure && make && make install, clean, unintall, run the unit tests, etc...

I will simply mention that when I update the README file so people don't miss
that file.

Hope this helps,
Youness.

On 02/15/2013 06:11 PM, Youness Alaoui wrote:
> Hi Daniel,
> 
> On 02/15/2013 11:27 AM, Daniel Lobo wrote:
>> 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?
>>
> Thanks for writing this, I'm sure others will find some of its content useful.
> As for instructions. Maybe I should write build instructions in the README file.
>>
>> 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.
> 
> haha, yes, libjingle is a huge huge mess. libnice itself was written so we could
> get rid of libjingle! You'll find libnice to be much easier to work with :)
> 
>>
>>
>> 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.
> Great! The README.win32 and VS support was added by "Filippo Della Betta" who
> sent his patches to this mailing list. I'm glad they were helpful to you! If you
> find anything was missing, let me know and we could enhance/modify the readme
> file to help others.
> As for linux, there were no build instructions because the "./configure && make
> && sudo make install" is the 'standard' way of compiling anything on Linux. If
> you need to compile stuff on linux, then you should know that magic sequence of
> commands! To me at least, explicitely saying it is kind of like saying in the
> windows instructions "in Visual Studio, go to menu build, and click the Build
> button" :)
> As you are new to linux, it's perfectly understandable that you didn't know
> this, but at least now, you do. I will add build instructions in the README file
> so other unexperienced liux users will not go through the same trouble as you did.
> As for the ./autogen.sh, that's also the standard way of generating the
> configure file. That's only necessary if you download the source from git, but
> you don't need to do it if you download a release version since the configure
> file is always pre-generated in those tarballs.
> 
>>
>> 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).
> As far as I remember, libnice has no dependencies other than glib. So you
> probably had to do apt-get install libglib-2.0-dev. There are also dependencies
> on gstreamer and on gupnp, but if those are not found during the ./configure
> stage, then their respective features will simply be disabled and libnice will
> compile without them.
> 
> 
> 
>>
>>
>> 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.
> The example there is more of a pseudo-code than an actual compilable example. It
> is only meant to be read and to allow you to understand which API functions to
> call and when. That's also why it couldn't compile and had missing variables, etc...
> Until very recently (thanks Bryce Allen who contributed it), we never had real
> examples with libnice. Most people would just read the documentation and the
> unit tests to see how to use the library.
> You can now find these examples here :
> http://cgit.collabora.com/git/user/kakaroto/libnice.git/tree/examples
> They will be included in the next release of libnice (to be released very soon).
> As you can see from the comment in the header of those files, they can be built
> with :
>  * Build:
>  *   gcc -o simple-example simple-example.c `pkg-config --cflags --libs nice`
> 
> pkg-config is the standard tool on linux for defining which compiler flags and
> options and libraries are needed when you compile a program that depends on the
> library.
> However, in the case of those examples, simply typing "make" will get them to
> compile now that they are part of libnice's build system.
> 
>>
>> 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).
>>
> Yep, libnice installs the file 'nice.pc' to /usr/lib/pkgconfig which allows
> pkg-config to find which version of libnice is installed, what C flags to pass
> to the compiler and what LD flags and dependent libraries to pass to the linker.
> As I said above, it's the standard way on linux of checking for dependencies and
> compiling programs with their dependent libraries. For example, libnice (and
> pretty much every other software out there) uses pkg-config to check for the
> existence and versions of their dependencies and to link with them. In the
> configure.ac file, you will see this line :
> PKG_CHECK_MODULES(GLIB, [dnl
>         glib-2.0 >= 2.13 dnl
>         gobject-2.0 >= 2.13 dnl
>         gthread-2.0 >= 2.13 dnl
>         gio-2.0 >= 2.13 dnl
>         ])
> This will check for all these modules (glib-2.0, gobject-2.0, gthread-2.0 and
> gio-2.0) and will store the appropriate C flags and LD flags and dependencies in
> GLIB_CFLAGS and GLIB_LIBS variables to be used in the makefile.
> 
> 
> 
>>
>> 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
>>
> 
> Thanks for that, this looks useful, would you mind if I included parts of it in
> the build instructions of the README ?
> 
>>
>> 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`
>>
> Yep, that would do the trick, it should be installed on your system though since
> I think pretty much everything would depend on it! If you want to compile
> something, you would usually install gcc, autotools and some -dev packages and I
> think pkg-config comes with them automatically as a dependency. :)
> 
>>
>> 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 :(
> Humm.. I don't know about pkg-config on windows, but was this needed or were the
> README.win32 instructions enough for you to get it to compile correctly on windows ?
> 
>>
>>
>> I hope some of this actually helps someone...
> It is, thanks for taking the time to write this email. I will use that to
> improve the README so others don't have to go through it the hard way.
> 
> Thanks,
> Youness.
> 
> 
> 
> 
> _______________________________________________
> nice mailing list
> nice at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/nice
> 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 263 bytes
Desc: OpenPGP digital signature
URL: <http://lists.freedesktop.org/archives/nice/attachments/20130215/73862d7e/attachment.pgp>


More information about the nice mailing list