3

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
javadpup
  • 31
  • 1
  • 3
  • 1
    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 Jun 22 '11 at 15:46
  • Second what @Grizzly said, we can not help unless you post the contents of your makefile. – Mark Jun 23 '11 at 14:12
  • `gtkmm.h` and`glibmm.h` are in `/usr/include/gtkmm-2.4/`? – Beta Jun 24 '11 at 17:00
  • 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 Jun 25 '11 at 07:39

2 Answers2

2

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.

Doruk
  • 385
  • 2
  • 12
1

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
karlphillip
  • 92,053
  • 36
  • 243
  • 426
  • Unfortunately that does not seem to fix the issue, it just returns the same error. That error only appears when I specify the path of gtkmm in the header file, otherwise it just returns an error that it can't find gtkmm, which I included all along. Thanks for the help anyways! – javadpup Jun 24 '11 at 18:13
  • Well, that works for me. Are you sure you have the headers of libglibmm and libgtkmm installed? `sudo apt-get install libglibmm-2.4-dev libgtkmm-2.4-dev` – karlphillip Jun 24 '11 at 18:15
  • After that, use `#include ` on your sources. – karlphillip Jun 24 '11 at 18:16
  • Yeah, both of those say they are installed when I use apt-get. I am beginning to think there is some problem with pkg-config, but I wouldn't know how start trying to fix that – javadpup Jun 24 '11 at 18:20
  • Add `-I/usr/include/glibmm-2.4` to your compilation line and tell us what's the next error. But make sure you are using `#include `, ok? – karlphillip Jun 24 '11 at 18:25
  • It just returns the error `g++ -c -o main.o main.cc In file included from main.cc:2: test.h:12: fatal error: gtkmm.h: No such file or directory compilation terminated.` The same one that I got in the beginning (sorry it is all squished together, don't know how to make a new line in comments) – javadpup Jun 24 '11 at 18:31
  • Ok, now also add `-I/usr/include/gtkmm-2.4` which is where gtkmm.h is located. Do this also for the test.o rule on your Makefile. – karlphillip Jun 24 '11 at 18:34