27

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>?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
multiholle
  • 3,050
  • 8
  • 41
  • 60
  • Related: *[What is the meaning of -lm in GCC?](https://stackoverflow.com/questions/44175151/what-is-the-meaning-of-lm-in-gcc)*, *[Why do you have to link the math library in C?](https://stackoverflow.com/questions/1033898/why-do-you-have-to-link-the-math-library-in-c)*, and *[GCC -lm -lz -lrt options - what are they about?](https://stackoverflow.com/questions/5663097/gcc-lm-lz-lrt-options-what-are-they-about)* – Peter Mortensen Nov 02 '22 at 23:08

7 Answers7

95
-I<search path to include files>
-L<search path to the lib file>
-l<libname>
Community
  • 1
  • 1
Kristofer
  • 3,201
  • 23
  • 28
  • indeed @debuti ... furthermore, seems that one can omit the space between the `I` or `L` and the `searchpath`, and put it all together like: `-I` – DarkCygnus Jul 04 '18 at 21:07
  • That doesn't answer the question, only regurgitating the (incomplete) documentation. A proper answer would at least address possible ***naming conventions*** used to derived the actual argument. What should the actual argument be? `-llibappindicator`? `-lappindicator`? Something else? – Peter Mortensen Nov 02 '22 at 22:31
19

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.

Vijay Mathew
  • 26,737
  • 4
  • 62
  • 93
  • 1
    That doesn't answer the question, only regurgitating the (incomplete) documentation. A proper answer would at least address possible ***naming conventions*** used to derived the actual argument. What should the actual argument be? `-llibappindicator`? `-lappindicator`? Something else? – Peter Mortensen Nov 02 '22 at 22:34
7

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
lijo
  • 311
  • 3
  • 5
  • What is supposed to happen by that command line invocation? How do those backticklies work? Is there some exchange using [standard input](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)) and [standard output](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_.28stdout.29)? Or not? In general, why is this necessary? Please respond by [editing (changing) your answer](https://stackoverflow.com/posts/12686188/edit), not here in comments (**** ***without*** **** "Edit:", "Update:", or similar - the answer should appear as if it was written today). – Peter Mortensen Nov 02 '22 at 23:03
6

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.

mah
  • 39,056
  • 9
  • 76
  • 93
QuantumMechanic
  • 13,795
  • 4
  • 45
  • 66
  • I added the libappindictaor-dev package. What do I have to use with gcc as -l argument? – multiholle May 16 '11 at 11:52
  • 1
    According to http://packages.ubuntu.com/hu/natty/i386/libappindicator-dev/filelist you need to use `-I/usr/include/libappindicator-0.1/libappindicator` – QuantumMechanic May 16 '11 at 12:39
6

What I do is:

pkg-config --list-all | grep indicator
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
hytromo
  • 1,501
  • 2
  • 27
  • 57
  • What is it supposed to do? An explanation would be in order. E.g., what is the idea/gist? From [the Help Center](https://stackoverflow.com/help/promotion): *"...always explain why the solution you're presenting is appropriate and how it works"*. Please respond by [editing (changing) your answer](https://stackoverflow.com/posts/7320100/edit), not here in comments (***without*** "Edit:", "Update:", or similar - the answer should appear as if it was written today). – Peter Mortensen Nov 02 '22 at 22:50
  • Is it a response to [manugupt1's answer](https://stackoverflow.com/questions/6016815/how-can-i-include-a-needed-c-library-using-gcc/6017057#6017057)? – Peter Mortensen Nov 02 '22 at 22:53
1

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
manugupt1
  • 2,337
  • 6
  • 31
  • 39
0

The default path for all c++ include files like library files and header files in ubuntu/linux are found in /usr/include/c++/11