I'm using Kdevelop 4.0 to make a new app, and now I'm trying to include the glib but I cannot do it.
I have installed via apt-get install in Ubuntu 10.04 and it's installed in /usr/include/glib-2.0, but when I try to include the library with
#include <glib.h>
and try to compile it, it tells me that "such file doesn't exists".
What am I doing wrong?
Thanks!
You need to pass the path to the glib libraries and headers to your compiler.
glib provides the pkg-config script to generate what you need. To compile correctly, you would need to do something like the following:
cc `pkg-config --cflags --libs glib-2.0` hello.c -o hello
This answer is basically a quick summary of what is provided in the glib documentation here:
http://developer.gnome.org/glib/2.28/glib-compiling.html
I'm not familiar with KDevelop, but if it's like Eclipse or Visual Studio, there is a menu for adding libraries and include folders to a project. Try the following:
Run pkg-conf --cflags glib-2.0
Add output to include directories for your project.
Run pkg-conf --libs glib-2.0
Add output to libraries path for your project.
A quick look on google suggests that you can find these menus at the following locations:
Include Directories
Automake manager> options> Includes> Directories
Library Directories
Automake Manager > Options >Libraries > Link Libraries
Related
I've some errors compiling C code with GTK widgets in Eclipse, indicating that gtk/gtk.h cannot be found. I've already installed GTK+2 and GTK+3; and also included the header paths for GTK but it seems that the Eclipse environment is still unable to find the required header.
Greatly appreciate any advice from the community!
You didn't provide enough information to actually know what is going on, but I guess the include paths you configured are somehow wrong.
My advice would be that you should use pkg-config to obtain the correct compiler flags instead of adding include dirs etc. manually.
This will give you a list of all packages, pkg-config knows are installed on your machine:
pkg-config --list-all
The GTK package should be something like gtk+-3.0
Use this to get the CFLAGS for use with GTK3:
pkg-config --cflags gtk+-3.0
And here is how to get the libraries for the linker stage:
pkg-config --libs gtk+-3.0
So instead of doing something like this:
# Don't do this
gcc -I... main.c
... use something like this:
gcc $(pkg-config --cflags gtk+-3.0) ... main.c
Read the man page of pkg-config for more informations.
There was an Eclipse plugin for pkg-config support, but it doesn't seem to work with Oxygen. I managed to get a building example with these settings, though Eclipse itself won't find the includes.
kplot is a UNIX programming library for plotting graphs on a Cairo surface. The source code is available here.
After downloading the source code I extraced it to the directory kplot-master and cd into it. Simple ls now shows
array.c
border.c
bucket.c
buffer.c
....
example0.c
example1.c
....
I am using Ubuntu 14.04 LTS. Cairo is installed in my system and I tested it by successfully compiling C codes available in [zetcode dot com slash gfx slash cairo slash cairobackends slash] (Sorry as I am not allowed to link more than two).
I am new to GTK and Cairo plotting library and would like help in the following directions:
I do not want to install kplot in my system.
I just want to learn how kplot uses Cairo.
When I use the following command:
gcc example0.c -o example `pkg-config --cflags --libs gtk+-3.0`
it produces the following error message:
example0.c:17:20: fatal error: compat.h: No such file or directory
#include "compat.h"
^
compilation terminated.
It will be very helpful if somebody shows me how to test those kplot examples without installing it.
There is no need to install.
First you will need to compile the kplot library. For that, cd to the kplot directory and run a make command. This will generate the file compat.h. After that you will be able to compile example by example with make example(n) command, or with gcc example(n).c -o example(n) `pkg-config --cflags --libs gtk+-3.0` libkplot.a -lbsd -lm command.
If you have GTK+-3.0 and Cairo dev libraries installed, everything should go well.
Just installed librsync using apt-get install librsync-dev on ubuntu. I can link other libraries like this pkg-config --libs --cflags glib-2.0 but I can't find librsync using pkg-config. How can I link it?
UPDATE: I very new to C and all this compiling linking stuff. Just learned how to find and link using pkg-config. But this librsync seems to be developed using different thing.
Your problem is not with C. The problem is most likely due to librsync NOT providing a package config file. Try:
pkg-config --list-all | grep -i rsync
If you get no response, librsync has no pkgconfig file available to the system. Instead of using pkg-config to link librsync, just add -lrsync to your gcc command line. E.g.:
gcc -Wall -o mynewprog mynewprog.c -lrsync
Resently I'm installed Opencv in my machine. Its working in python well(I just checked it by some eg programs). But due to the lack of tutorials in python I decided to move to c. I just run an Hello world program from http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/
while compiling I got the following error
hello-world.c:4:16: fatal error: cv.h: No such file or directory
compilation terminated.
I'm new in opencv
Qn : Could you please report what may be the problem - and how I run my helloworld program in c?
Your compiler cannot find your cv.h include file. If you installed from your package manager, it is probably in /usr/include/opencv/. You need to add that your include search path. If you are compiling from the command line use -I to specify additional include directories. It will be something like -
gcc -I /usr/include/opencv/ -o helloworld helloworld.c
If you are using Eclipse,
Right click on the project and select properties.
Select C/C++ General -> Path and Symbols.
Select Includes tab.
In Languages list, select 'GNU C' or 'GNU C++' depending on which you are using.
Press 'Add...' button and add /usr/include/opencv/
Save and rebuild.
You need to show compiler path to cv.h file. The quick way to find it is to do (on Ubuntu):
find /usr -name "cv.h"
/usr/local/include/opencv/cv.h
Just add this to the compiler:
gcc -I/usr/local/include/opencv -o helloworld helloworld.c
Since you asking this question your compiler might also have problems linking your program to opencv libraries. Just do the same thing only for library files:
find /usr -iname "libopencv*"
/usr/local/lib/libopencv_flann.so
...
add this folder the same way and specify libraries you want to use:
gcc helloworld.c -I/usr/local/include/opencv -L/usr/local/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -o helloworld
that should probably compile. There is a also a short cut you can take and instead of all that steps just use the following command
gcc helloworld.c `pkg-config --cflags --libs opencv` -o helloworld
that should take care of all the work of locating required files for you and let you focus on the fun coding part.
maybe you just installed the opencv package.
But, as you want to use opencv in your C program, you may also install the package named just like opencv-devel. If you haven't, install it and than use it as #iagreen said.
Best wishes to you.
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>?
-I<search path to include files>
-L<search path to the lib file>
-l<libname>
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.
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.
What I do is:
pkg-config --list-all | grep indicator
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.
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