3
votes

I am currently trying to write a simple program with gtkmm, but I am running into issues when I try to compile it. I have a few simple files: main.cc which only contains the main function, test.cc and test.h which define a class based Gtk::Window with a pair of buttons in it, and finally a simple makefile.

The problem arises when I try to compile the makefile, it returns:

In file included from main.cc:2:
test.h:12: fatal error: gtkmm.h: No such file or directory

If I then replace #include <gtkmm.h> with #include <gtkmm-2.4/gtkmm.h> it returns the error:

In file included from test.h:12,
                 from main.cc:2:
/usr/include/gtkmm-2.4/gtkmm.h:87: fatal error: glibmm.h: No such file or directory

I been searching for a solution for a while and have looked around online for it, but for other users who had a similar problem, it was caused by not including `pkg-config --cflags --libs gtkmm-2.4` in their makefile. Unfortunately this was not the source of my problem, as I have had it in mine all along.

The strangest part is that it works when I don't use a makefile. If I take the main function from my main.cc and put it into my test.cc file, then type:

g++ test.cc -o output `pkg-config --cflags --libs gtkmm-2.4`

into the console, it works fine. This is only a temporary fix, as I am coming to the point where I need to have more than one class. I don't know if this is is some problem with the installation of make or gtkmm, and have tried re-installing both, to no avail. I don't know what else to try.

Finally if it helps I am running Ubuntu 10.10, with g++ version 4.4.5

Thank you for any help

The makefile is as follows:

main: main.o
    @echo "Main"
    @g++ -g main.cc test.o -o output `pkg-config --cflags --libs gtkmm-2.4` 
test.o:
    @echo "Test"
    @g++ test.cc -o test.o `pkg-config --cflags --libs gtkmm-2.4`
clean:
    @clear
    @rm -f *.o
2
It might help, if you would post the code of your makefile or the output for the compiler call, so we can see how exactly the compiler is called.Grizzly
Second what @Grizzly said, we can not help unless you post the contents of your makefile.Mark
gtkmm.h andglibmm.h are in /usr/include/gtkmm-2.4/?Beta
You can run make -n to see what command it is using to compile. This should show you how your working command line differs from what make is trying to do. You can also run pkg-config --cflags --libs gtkmm-2.4 to see what the output is and verify that all the proper include directories are listed.ptomato

2 Answers

2
votes

I had the same problem and I have solved it by adding pkg-config gtkmm-3.0 --cflags --libs to both steps of build (compilation and linking). My makefile:

CC=g++
CFLAGS=-c -Wall 
LDFLAGS=
SOURCES=WatsonGui.cpp
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=watsonGui

all: $(SOURCES) $(EXECUTABLE) 

$(EXECUTABLE): $(OBJECTS) 
    $(CC) $(LDFLAGS) $(OBJECTS) -o $@ `pkg-config gtkmm-3.0 --libs`

.cpp.o:
    $(CC) $(CFLAGS) $< -o $@ `pkg-config gtkmm-3.0 --cflags`

clean:
    rm -rf *.o watsonGui 

Note that the type of quotation marks used for pkg-config is important, if you use ' instead of ´ it doesn't work.

P.S.: I'm a newbie on makefiles so I am not perfectly sure about what I did.

1
votes

This error:

/usr/include/gtkmm-2.4/gtkmm.h:87: fatal error: glibmm.h: No such file or directory`

suggests that you must add glibmm-2.4 to pkg-config search:

main: main.o
    @echo "Main"
    @g++ -g main.cc test.o -o output `pkg-config --cflags --libs gtkmm-2.4 glibmm-2.4` 
test.o:
    @echo "Test"
    @g++ test.cc -o test.o `pkg-config --cflags --libs gtkmm-2.4 glibmm-2.4`
clean:
    @clear
    @rm -f *.o