[Nice] Compilation of libnice code

Daniel Lobo dlobo at student.dei.uc.pt
Mon Feb 18 04:54:01 PST 2013

Hello again :)

I got pkg-config to work with libnice under Eclipse in Windows. Starting 
with the hardest part:

Like you said, pkg-config needs libnice to build a nice.pc file. This 
should be located in "libnice/nice". In my build, though, there was only 
a nice.pc.in file with what I guess are placeholders for the real thing. 
Therefore, I created nice.pc manually (based on the final nice.pc file 
in Linux).

1. My folder for libnice is c:/app/libnice. Modify this path according 
to your install.
2. The several built dlls were located in 
libnice/win32/vs9/libnice/bin/Win32_Release, as I used Visual Studio. 
Modify this path according to the way you compiled the libraries.
3. There might be some missing include paths. This worked for my 
examples, but unfortunately I have no way of knowing if this is enough.
4. The version numbers were copied from the Linux file :p

The nice.pc file is between [start] and [end]:


Name: libnice
Description: ICE library
Requires: glib-2.0 >= 2.10.0
Libs: -L${libdir} -lnice -pthread -lgthread-2.0 -lintl -lgio-2.0 
-lgobject-2.0 -lglib-2.0
Cflags: -pthread -I${prefix}/glib/include/glib-2.0 
-I${prefix}/glib/include/ -I${includedir} -I${includedir}/nice 

Now, instructions for pkg-config in Windows and Eclipse (at least this 
is what I did):

1. download the pre-compiled pkg-config from:

2. extract it (in my case to c:/app/pkg-config)

3. install the pkg-config plugin in Eclipse
     - "Help -> Install New Software..."
     - "Work with": 
     - select and install the plugin

4. configure pkg-config
     - go to project Properties -> C/C++ Build -> Pkg-config tab
     - select "Advanced..." on the right
     - set the path for the pkg-config executable
     (in my case, C:\app\pkg-config\bin\pkg-config.exe)
     - select "Append to (PKG_CONFIG_PATH)"
     - add the "libnice/glib/lib/pkgconfig" and "libnice/nice" folders 
using "New..."
     - press "OK"

5. a list of checkboxes should appear, so select "nice" and now the 
includes and libraries of your project should be set.

This should work, as long as I didn't skip any steps in the explanation :)

If you don't use Eclipse, the usual way to use pkg-config in Windows 
should be to set an environment variable called "PKG_CONFIG_PATH" with 
both "libnice/glib/lib/pkgconfig" and "libnice/nice" paths. In fact, 
Eclipse was supposed to see this variable, but in my case it didn't, so 
I added both manually, as seen before.

- Daniel

On 16-02-2013 00:56, Daniel Lobo wrote:
> Wow, sincere thanks for explaining everything :)
> I had done the ./configure, make, sudo make install sequence before 
> (though only now I memorized it), but autogen.sh was a new for me 
> (well, maybe I've used it before while following instructions, but I 
> can't remember :p). And yes, I downloaded libnice from the git repo, 
> so that explanation about autogen might be useful in the future. Also, 
> I've completely missed the INSTALL file! But yes, it's there :)
> Indeed, I believe I installed libglib-2.0-dev. It was probably the 
> only one, then. I saw those other two mentioned in the short Linux 
> readme, but didn't install them.
> Those examples will also be useful. Thank you! And also "thank you" to 
> everyone that contributed to the instructions and examples.
> I wouldn't mind at all. Feel free to use and modify what I wrote. By 
> the way, I should have mentioned that my Linux is Mint 13 (Maya), 
> though that might not make much difference, instructions-wise. Same 
> for Eclipse (in this case, the Indigo version), as the plugin install 
> should work in every version.
> libnice compiled correctly in Windows with just the readme 
> instructions (using the Visual Studio solution). The problem comes 
> afterwards, when compiling user code that uses the library. It is 
> possible that the solution contains what is needed for compiling it 
> (I'm definitely not VS-savvy :) ), but if I want to use Eclipse, for 
> example, I would need to know what libraries and paths to include. I 
> will eventually try it to lookup how to correctly setup things for 
> pkg-config in Windows, as it would solve this problem; it also seems 
> interesting from your descriptions.
> I think the extra effort with readmes and examples would help other 
> people like me immensely :)
> Much appreciated!
> - Daniel
> On 15-02-2013 23:37, Youness Alaoui wrote:
>> 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 :
>>>          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
>> _______________________________________________
>> nice mailing list
>> nice at lists.freedesktop.org
>> http://lists.freedesktop.org/mailman/listinfo/nice
> _______________________________________________
> nice mailing list
> nice at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/nice

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/nice/attachments/20130218/431ea39e/attachment-0001.html>

More information about the nice mailing list