I am trying to compile a GTKmm C++ program using g++ (clang), however I can't seem to find the header files that I need. I have run the installation .sh
file for GTK+, and I have also tried directly installing GTKmm via Homebrew, but I am still getting this error:
fatal error: 'gtkmm/button.h' file not found
I thought it would be as simple as adding an include directory, but I have tried searching my hard drive for GTK-related things and am still not finding anything. What should I do?
I am using a Macbook running MacOS Big Sur.
Update: My code is this:
helloworld.h
#ifndef GTKMM_EXAMPLE_HELLOWORLD_H
#define GTKMM_EXAMPLE_HELLOWORLD_H
#include <gtkmm/button.h>
#include <gtkmm/window.h>
class HelloWorld : public Gtk::Window {
public:
HelloWorld();
virtual ~HelloWorld();
protected:
//Signal handlers:
void on_button_clicked();
//Member widgets:
Gtk::Button m_button;
};
#endif
helloworld.cpp
#include "helloworld.h"
#include <iostream>
HelloWorld::HelloWorld()
: m_button("Hello World") // creates a new button with label "Hello World".
{
// Sets the border width of the window.
set_border_width(10);
// When the button receives the "clicked" signal, it will call the
// on_button_clicked() method defined below.
m_button.signal_clicked().connect(sigc::mem_fun(*this,
&HelloWorld::on_button_clicked));
// This packs the button into the Window (a container).
add(m_button);
// The final step is to display this newly created widget...
m_button.show();
}
HelloWorld::~HelloWorld()
{
}
void HelloWorld::on_button_clicked()
{
std::cout << "Hello World" << std::endl;
}
main.cpp
#include "helloworld.h"
#include <gtkmm/application.h>
int main (int argc, char *argv[]) {
auto app = Gtk::Application::create(argc, argv, "org.gtkmm.example");
HelloWorld helloworld;
//Shows the window and returns when it is closed.
return app->run(helloworld);
}
This code comes from here.
I am compiling by first navigating to the directory of the files listed above, and running g++ main.cpp -o helloworld
.
Because I have installed Homebrew, g++ uses clang++.
Ok, I have figured it out.
I needed to install both GTK+ and GTKmm via Homebrew. This put the library into /usr/local/include
. Note that the question code still won't work, because it is using the wrong directory (I installed gtk+3 and gtkmm3). Refer to this answer for more information.