tags:

views:

1335

answers:

3

I'm trying to compile a simple program, with

#include <gtkmm.h>

The path to gtkmm.h is /usr/include/gtkmm-2.4/gtkmm.h g++ doesn't see this file unless I specifically tell it -I /usr/include/gtkmm-2.4. My question is, how can I have g++ automatically look recursively through all the directories in /usr/include for all the header files contained therein, and why is this not the default action?

+1  A: 

You can't. The whole point of include paths is so you can pick and choose what you want and what versions.

What you could do is..

#include <gtkmm-2.4/gtkmm.h>

Which would achieve the same effect.

Adam Hawes
The problem with this is that gtkmm.h itself just includes a bunch of other headers with a path relative to its location that g++ cannot find .. :/. It is irritating.I guess I could go through and replace all the paths in gtkmm.h, but I am hoping for another solution.
endeavormac
@endeavormac: what form do the relative includes take in gtkmm.h? Basically, you are expected to specify the directory where gtkmm.h is found via -I and it will then, most likely, work correctly. Without that, it won't. Full stop - or period, if you prefer. Why do want to battle against the design?
Jonathan Leffler
What Jon said :)
Adam Hawes
+1  A: 

I guess you are not using a makefile? The only thing that could be annoying is having to type the long -I option each time you compile your program. A makefile makes it a lot easier.

For example, you could modify the hello world makefile from wikipedia to something like the following:

INC=-I/usr/include/gtkmm-2.4/

helloworld: helloworld.o
    g++ -o $@ $<

helloworld.o: helloworld.c
    g++ $(INC) -c -o $@ $<

.PHONY: clean

clean:
    rm -f helloworld helloworld.o
PolyThinker
+5  A: 

In this case, the correct thing to do is to use pkg-config in your Makefile or buildscripts:

# Makefile
ifeq ($(shell pkg-config --modversion gtkmm-2.4),)
  $(error Package gtkmm-2.4 needed to compile)
endif

CXXFLAGS += `pkg-config --cflags gtkmm-2.4`
LDLIBS += `pkg-config --libs gtkmm-2.4`

BINS = program
program_OBJS = a.o b.o c.o

all: $(BINS)

program: $(program_OBJS)
        $(CXX) $(LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@

# this part is actually optional, since it's covered by gmake's implicit rules
%.o: %.cc
        $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@

If you're missing gtkmm-2.4, this will produce

$ make
Package gtkmm-2.4 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gtkmm-2.4.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gtkmm-2.4' found
Makefile:3: *** Package gtkmm-2.4 needed to compile.  Stop.

Otherwise, you'll get all the appropriate paths and libraries sucked in for you, without specifying them all by hand. (Check the output of pkg-config --cflags --libs gtkmm-2.4: that's far more than you want to type by hand, ever.)

ephemient
I guess I just opened up a whole new headache for me to read about. Alright, thanks
endeavormac