Search code examples
c++gtkmmmanjaro

Manjaro Linux cannot open source file "gtkmm.h"


I have been trying to set up my coding environment for GUI development in c++ recently, with little success. I use Manjaro Linux with Visual Studio Code, but for some reason, I always seem to get include errors when including files that I know are there.

Most recently, I tried to set up gtkmm-4.0 by installing the package and the documentation. I double checked in /usr/include/ to ensure the packages were all present, but I still am getting include errors: cannot open source file "gtkmm.h" and gtkmm.h:No such file or directory

At this point, all the code I have is:

#include <gtkmm.h>
#include <iostream>

int main(int argc, char* argv[]){

    return 0;
}

Makefile:

exec = game.out
sources = $(wildcard src/*.cpp)
objects = $(sources:.cpp=.o)
flags = -g $(shell pkg-config gtkmm-4.0 --cflags)
libs = $(shell pkg-config gtkmm-4.0 --libs)


$(exec): $(objects)
    g++ $(objects) $(flags) -o $(exec) $(libs)

%.o: %.cpp include/%.h
    g++ -c $(flags) $< -o $@

install:
    make
    cp ./game.out /usr/local/bin/game

clean:
    -rm *.out 
    -rm *.o
    -rm src/*.o

I have scoured the internet for answers, but everything I found was either for a different os/environment or just didn't

@Galik and @John helped me solve this!

What I had to do was use g++ src/main.cpp -o main $(pkg-config gtkmm-4.0 --cflags --libs) to compile my code, then run the executable.

Thank you both for your help and guidance!!


Solution

  • You need to install pkg-configand add this to the compiler flags in your Makefile:

    flags = -g $(shell pkg-config gtkmm-2.4 --cflags)
    libs = $(shell pkg-config gtkmm-2.4 --libs)
    
    # ...
    
    $(exec): $(objects)
        g++ $(objects) $(flags) -o $(exec) $(libs)
    

    The tool pkg-config has a database of the correct paths for supporting libraries.

    Depending on your version if gtkmm, you may need to substitute gtkmm-3.0, if you have version 3.0.