3

私はC++とgtkmmを初めて使用します。私は現在、ウィンドウとボタンを使用してオンラインで見つけたチュートリアルをコンパイルしようとしています。Ubuntu12.04でコンパイルしています。1つのファイルを正常にコンパイルできますが、Makefileを使用して複数のファイルをコンパイルしようとすると、理解できないエラーが発生します。

sarah@superawesome:~/gtkexample$ make
g++ -c main.cc
In file included from HelloSarah.h:4:0,
                 from main.cc:1:
/usr/include/gtkmm-3.0/gtkmm/button.h:7:28: fatal error: glibmm/ustring.h: No such file or directory
compilation terminated.
make: *** [main.o] Error 1

私は本当にエラーを理解していません、私は何時間も探していました。私の問題についての助けや洞察を本当にいただければ幸いです。

これらは私の3つのファイルとMakefileです:

#ifndef GTKMM_HELLOSARAH_H
#define GTKMM_HELLOSARAH_H

#include <gtkmm-3.0/gtkmm/button.h>
#include <gtkmm/window.h>

class HelloSarah : public Gtk::Window
{

public:
  HelloSarah();
  virtual ~HelloSarah();

protected:
  //Signal handlers:
  void on_button_clicked();

  //Member widgets:
  Gtk::Button m_button;
};

#endif 

main.cc

#include "HelloSarah.h"
#include <gtkmm/application.h>

int main (int argc, char *argv[])
{
  Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(argc, argv,     "org.gtkmm.example");

  HelloSarah hellosarah;

  //Shows the window and returns when it is closed.
  return app->run(hellosarah);
}

およびHelloSarah.cc

#include "helloSarah.h"
#include <iostream>

HelloSarah::HelloSarah()
: m_button("Hello Sarah")   // creates a new button with label "HelloSarah".
{
  // 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,
          &HelloSarah::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();
}

HelloSarah::~HelloSarah()
{
}

void HelloSarah::on_button_clicked()
{
  std::cout << "Hello Sarah" << std::endl;
}

そして最後に私のMakefile:

app:            main.o HelloSarah.o
                g++ -o app main.o HelloSarah.o

main.o:         main.cc HelloSarah.h
            g++ -c main.cc

HelloSarah.o:   HelloSarah.cc HelloSarah.h
            g++ -c HelloSarah.cc

clean:      
            rm -f *.o app
4

2 に答える 2

7

次の例のincludeステートメントは正しくありません。これは、ファイルパスが標準の/ usr / include /ディレクトリから相対的であるためにのみ機能しますが、 button.hのincludeステートメントはそうではないため、エラーメッセージが表示されます。

#include <gtkmm-3.0/gtkmm/button.h>

必要なインクルードファイルと共有オブジェクトがどこにあるかをg++に伝える必要があります。pkg-configの出力を使用してその仕事をすることができます。

pkg-config --cflags --libs gtkmm-3.0

g++コマンド全体はそのようなものでなければなりません。

g++ `pkg-config --cflags --libs gtkmm-3.0` -c HelloSarah.cc

その後、gtkmmHelloWorldのinclude行を使用するだけです

#include <gtkmm/button.h>
于 2013-01-27T00:10:01.267 に答える
3

私もこの問題を抱えていましたUbuntu

ソリューション:

sudo apt-get install libgtkmm-3.0-dev

必要に応じて任意のバージョンを使用できます。

于 2017-11-01T06:10:32.813 に答える