LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   C, pkg-config, conflicting header locations (https://www.linuxquestions.org/questions/programming-9/c-pkg-config-conflicting-header-locations-730490/)

seandalton0 06-03-2009 03:35 PM

C, pkg-config, conflicting header locations
 
I've never come across this before, but I'm using pkg as follows:

Code:

`pkg-config --cflags --libs gtk+-2.0 libgnome-2.0 gnome-desktop-2.0`
now, in both the libgnome-2.0 directory, and gnome-desktop-2.0 directory there exists a "libgnome" subdirectory. When I try to import the two header files I need:

Code:

#include <libgnome/libgnome.h>
#include <libgnome/gnome-desktop-item.h>

there seems to be a conflict when compiling:

Code:

main.c:5:31: error: libgnome/libgnome.h: No such file or directory
main.c:6:41: error: libgnome/gnome-desktop-item.h: No such file or directory

When I use just one or the other it seems to compile fine.
Here are the two files I need:

Code:

./libgnome-2.0/libgnome/libgnome.h
./gnome-desktop-2.0/libgnome/gnome-desktop-item.h

Am I doing something wrong here? Unfortunately my C/Linux knowledge is pretty limited and this project is the first time I'm really diving into building a gnome app. Thank you in advance for any insight.

dwhitney67 06-04-2009 09:20 AM

You failed to post how you were compiling your source file, nor did you post the output given by the pkg-config command.

If you are using a Makefile, at a minimum it should look something like:
Code:

APP    = MyApp

SRCS    = main.c
OBJS    = $(SRCS:.c=.o)

CFLAGS  = `pkg-config --cflags gtk+-2.0 libgnome-2.0 gnome-desktop-2.0`
LDFLAGS = `pkg-config --libs  gtk+-2.0 libgnome-2.0 gnome-desktop-2.0`

all: $(APP)

$(APP): $(OBJS)
        $(CC) $^ $(LDFLAGS) -o $@

.c.o:
        $(CC) $(CFLAGS) -c $<

Try it out, and reply back if you still have trouble.

P.S. I am assuming you have the gtk+-2.0, libgnome-2.0, and gnome-desktop-2.0 development packages installed on your system.

knudfl 06-04-2009 09:50 AM

#include <header>
means : look in '/usr/include/' for the header.
( And in other include path's ).

So I guess you will have to write :

#include <libgnome-2.0/libgnome/libgnome.h>
#include <gnome-desktop-2.0/libgnome/gnome-desktop-item.h>

EDIT : See post # 2 for correct solution.
.....

dwhitney67 06-04-2009 11:43 AM

Quote:

Originally Posted by knudfl (Post 3563000)
#include <header>
means : look in '/usr/include/' for the header.
( And in other include path's ).

So I guess you will have to write :

#include <libgnome-2.0/libgnome/libgnome.h>
#include <gnome-desktop-2.0/libgnome/gnome-desktop-item.h>

.... that's where the files are located.
.....

There should not be a need to specify the libgnome-2.0 in the include-path if -I/usr/include/libgnome-2.0 is specified with the gcc CFLAGS when the file is compiled.

seandalton0 06-04-2009 04:42 PM

Sorry, I'm compiling from the CLI, not through a makefile. However, for a temporary fix, I've just specified the absolute location of both the header files.

I'm assuming that this issue has been addressed by gnome devs, if you check the GIT tree repositories for gnome (http://git.gnome.org/cgit/gnome-desktop/tree/), and check under "gnome-desktop", you might notice there's no longer a "libgnome" directory, so instead of "./libgnome/gnome-desktop.item.h" the header location would be "./libgnome-desktop/libgnome/gnome-desktop-item.h". Which I assume would correct the problem, now that there are two distinct paths to each header.


For reference, here's the output of pkg-config:
Code:

pkg-config --cflags --libs gtk+-2.0 libgnome-2.0 gnome-desktop-2.0
-DORBIT2=1 -pthread -I/usr/include/gtk-2.0 -I/usr/lib64/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/libgnome-2.0 -I/usr/include/orbit-2.0 -I/usr/include/gconf/2 -I/usr/include/gnome-vfs-2.0 -I/usr/lib64/gnome-vfs-2.0/include -I/usr/include/libbonobo-2.0 -I/usr/include/dbus-1.0 -I/usr/lib64/dbus-1.0/include -I/usr/include/bonobo-activation-2.0 -I/usr/include/gnome-desktop-2.0 -I/usr/include/libgnomeui-2.0 -I/usr/include/startup-notification-1.0 -I/usr/include/libart-2.0 -I/usr/include/gnome-keyring-1 -I/usr/include/libbonoboui-2.0 -I/usr/include/libgnomecanvas-2.0 -I/usr/include/libxml2 -I/usr/include/gail-1.0  -pthread -lgnome-desktop-2 -lgnomeui-2 -lSM -lICE -lstartup-notification-1 -lbonoboui-2 -lgnomevfs-2 -lgnomecanvas-2 -lgnome-2 -lpopt -lbonobo-2 -lbonobo-activation -lORBit-2 -lart_lgpl_2 -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lgdk_pixbuf-2.0 -lpangocairo-1.0 -lcairo -lpango-1.0 -lfreetype -lz -lfontconfig -lgconf-2 -lgthread-2.0 -lrt -lgmodule-2.0 -lgobject-2.0 -lglib-2.0

Quote:

P.S. I am assuming you have the gtk+-2.0, libgnome-2.0, and gnome-desktop-2.0 development packages installed on your system.
Yes I do, hence:
Quote:

When I use just one or the other it seems to compile fine.

dwhitney67 06-04-2009 05:00 PM

1 Attachment(s)
Try to use the Makefile I provided earlier, because I think you are doing something fundamentally wrong; there is no reason I can think of that would preclude GCC from finding the distinct headers files.

For the Makefile I provided earlier, copy/paste it to a file called Makefile (using your favourite editor), then save it. If you are not familiar with Makefiles, then one thing you must be aware of is that the statements that follow the entry-points of the Makefile must be preceded with a tab-space... not regular white-space.

To prove that GCC does not have trouble finding two distinct header files, I have attached a small project that employs a Makefile to compile a simple app that includes two header files: one in include/one/same, the other in include/two/same. All I had to provide GCC was a -I./include/one and a -I./include/two.

The main.c program looks like:
Code:

#include <same/headerOne.h>
#include <same/headerTwo.h>

int main()
{
  functionOne();
  functionTwo();
  return 0;
}

See for yourself...

P.S. Because LQ limits to which type of attachment I can include, the attached file is actually a tar-ball. After downloading it, go to the folder where it is, and run these commands:
Code:

tar xvf foo.txt
cd foo
make



All times are GMT -5. The time now is 09:33 PM.