Need clarification on Installing Linux header files

Posted on 2011-04-20
Last Modified: 2012-05-11
I'm new to c and Linux so I would like some clarification about: (1) why software installs the way it does and (2) what I need to do to use the software.

I'm modifying an existing c program and I wanted to add json processing to it.  Since I'm running openSUSE, I installed json-glib from their web site, did a search on json-glib, and used the one-click install to installl json-glib-devel.  Documentation says to include the following in the c program:

#include <json-glib/json-glib.h>

But that gives a compile error that says it can't be found... which makes sense because it's in json-glib-1.0/json-glib/json-glib.h.   Ok, so I change it to:

#include <json-glib-1.0/json-glib/json-glib.h>

Then I get an error that other header files don't exist because the includes in json-glib.h are:

#include <json-glib/json-types.h>
#include <json-glib/json-generator.h>
#include <json-glib/json-parser.h>
#include <json-glib/json-version.h>
#include <json-glib/json-enum-types.h>

Which is again going to the /usr/include/json-glib directory that doesn't exist.  So I'm wondering if I'm supposed to set up some kind of an alias and if so, also wondering why that isn't taken care of by some part of the install program.  

Anyway, if someone could shed a little light on this and tell me what's going on and what I need to do to fix it, I would really appreciate it.  Part of this is getting  json installed and working but another part is just a clarification of how this sort of thing is done on Linux.
Question by:StarDusterII

    Author Comment

    Ok, interesting... I was messing with symbolic links and created a link from /usr/include/json-glib-1.0/json-glib to /usr/include/json-glib.  So, that made all the json-glib includes happy but in json-enum-types.h it has:

    #include <glib-object.h>

    Now, that file is actually in /usr/include/glib-20 but since #include <glib-object.h> is not referencing its own folder, the symbolic link approach won't work there.  So, I'm wondering how these were supposed to work together at all.  Still confused...
    LVL 38

    Expert Comment

    > that file is actually in /usr/include/glib-20
    # cd /usr/include
    # ln -s /usr/include/glib-20/*.h  .

    Author Comment

    Thanks for the syntax, but first is this a normal thing to have to do to get things to compile?  Why are headers in one directory and you have to point at another?

    Anyway, there are directories in /usr/include/gllib-20 too so *.h won't work.  I used:

    ln -s /usr/include/glib-20 .

    The files look like they are in the right place but still get a compile error.

    linux-cwry:/home/stever/Projects/ComServer/ComServer # dir /usr/include/glib*
    total 24
    drwxr-xr-x 2 root root 4096 2010-10-30 06:58 gio
    drwxr-xr-x 2 root root 4096 2010-10-30 06:58 glib
    -rw-r--r-- 1 root root 2854 2010-07-05 08:15 glib.h
    -rw-r--r-- 1 root root 1474 2010-07-05 08:15 glib-object.h
    -rw-r--r-- 1 root root 3613 2010-07-05 08:15 gmodule.h
    drwxr-xr-x 2 root root 4096 2010-10-30 06:58 gobject

    linux-cwry:/home/stever/Projects/ComServer/ComServer # make
    gcc -MMD -g -Wall -Wextra -Werror -Wno-unused-parameter -c src/commands.c -o build/commands.o
    src/commands.c:48:25: fatal error: glib-object.h: No such file or directory
    compilation terminated.
    make: *** [build/commands.o] Error 1

    Author Comment

    I guess I should have included the includes:

    #include <glib-object.h>
    #include <json-glib/json-glib.h>

    I can see the glib-object.h in terminal, like the example above, but why can't I see it in Nautilus?
    LVL 32

    Accepted Solution

    you pass the base include folder 'json-glib-1.0' to gcc with -I option. then the compiler finds all the included files cause they were relative to this folder. if you were using a makefile you add the -I 'json-glib-1.0 to the cflags. if using an ide like eclipse you can add the include path to the project properties.


    Author Comment

    Sara, one of the things I hoped to get out of this is why is it done this way?... just so you can reference json-glib in your program and take care of new versions without changing the code?
    LVL 32

    Expert Comment

    i don't know whether i understand your q. but you should see that a new version of a library not necessarily is fully compliant to version before and that developers must have the possibility to have two or more versions parallel on their systems. so putting the version number into the folder name is not the most elegant way but could easily be changed if you don't need it.


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
    Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
    The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
    The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now