?
Solved

Need clarification on Installing Linux header files

Posted on 2011-04-20
7
Medium Priority
?
577 Views
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.
0
Comment
Question by:StarDusterII
  • 4
  • 2
7 Comments
 

Author Comment

by:StarDusterII
ID: 35435299
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...
0
 
LVL 38

Expert Comment

by:wesly_chen
ID: 35435415
> that file is actually in /usr/include/glib-20
# cd /usr/include
# ln -s /usr/include/glib-20/*.h  .
0
 

Author Comment

by:StarDusterII
ID: 35439654
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
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

Author Comment

by:StarDusterII
ID: 35439723
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?
0
 
LVL 35

Accepted Solution

by:
sarabande earned 2000 total points
ID: 35440333
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.

Sara
0
 

Author Comment

by:StarDusterII
ID: 35453362
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?
0
 
LVL 35

Expert Comment

by:sarabande
ID: 35762912
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.

Sara
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month14 days, 2 hours left to enroll

807 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