I am trying to compile the simple C example from this tutorial on Ubuntu using GCC. What do I have to use as arguments for GCC to include the needed libraries for #include <libappindicator/app-indicator.h>?
-
Related: What is the meaning of -lm in GCC?, Why do you have to link the math library in C?, and GCC -lm -lz -lrt options - what are they about?Peter Mortensen– Peter Mortensen2022-11-02 23:08:29 +00:00Commented Nov 2, 2022 at 23:08
7 Answers
-I<search path to include files>
-L<search path to the lib file>
-l<libname>
3 Comments
I or L and the searchpath, and put it all together like: -I<searchpath to include files>-llibappindicator? -lappindicator? Something else?Use the -l command line option. You can specify the library search path with the -L option. E.g:
gcc -o myprogram -lfoo -L/home/me/foo/lib myprogram.c
This will link myprogram with the static library libfoo.a in the folder /home/me/foo/lib.
3 Comments
-llibappindicator? -lappindicator? Something else?-L/path/to/libname but -lname.lfoo -> libfoo.a convention a bit surprising/hard to decipher at first. You can also link using the full path to the lib file, ie -"/home/me/foo/lib/libfoo.a"Use:
gcc example.c -o example `pkg-config --cflags --libs appindicator-0.1`
pkg-config will fetch the required include and library flags for libappindicator and its dependencies. This assumes libappindictaor-dev package is already installed.
1 Comment
If you used apt-get, Synaptic Package Manager, etc. to get the appindicator library (vs. building it from source), did you only install the libappindicator1 package or did you also install libappindicator-dev to get the libappindicator header files? Linux packages very often have split the runtime libraries from the compile-time headers. That way people who only need the libraries to satisfy a dynamic link don't have to install unneeded headers. But since you're doing development you need those headers and therefore need the libappindicator-dev package as well.
2 Comments
-I/usr/include/libappindicator-0.1/libappindicatorWhat I do is:
pkg-config --list-all | grep indicator
2 Comments
You are trying to make a GTK app, and the previous solutions are as applicable anywhere like using the -l option and -I option,
However, for GTK applications, you may also use pkg-config which makes it easier as your paths can be predefined.
An interesting example can be found in http://developer.gnome.org/gtk/2.24/gtk-compiling.html