Undefined Reference to `ExampleWindow::ExampleWindow()`

I've asked this at Stack Overflow but my question was marked as a duplicate and when I go to the link where they say my question is already answered there, I can't solve the problem because I don't really know what causes it. So, Here am I.

I code on Linux and compile with g++. I use gtkmm-3.16 to be precise. But I got the code from a gtkmm documentation for version 3.12. But I know that this error has nothing to do with gtkmm right?

This is the error message

1
2
3
4
5
6
ander@Ander:~/C++_Programming/test$ g++ main.cc -o main `pkg-config gtkmm-3.0 --cflags --libs`
/tmp/ccZE6Q0g.o: In function `main':
main.cc:(.text+0x7b): undefined reference to `ExampleWindow::ExampleWindow()'
main.cc:(.text+0xb6): undefined reference to `ExampleWindow::~ExampleWindow()'
main.cc:(.text+0x127): undefined reference to `ExampleWindow::~ExampleWindow()'
collect2: error: ld returned 1 exit status


Below are the files. I compile main.cc not examplewindow.cc so I know I'm on the right track except that I stopped progressing further learning C++ and GTKMM when I got the compilation error message above which I can't make any sense out of.

examplewindow.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include <gtkmm.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  virtual ~ExampleWindow();

protected:
  //Signal handlers:
  bool on_timeout();
  void on_button_close();

  //Child widgets:
  Gtk::Box m_VBox;
  Gtk::Entry m_Entry;
  Gtk::Button m_Button_Close;
};

#endif //GTKMM_EXAMPLEWINDOW_H 


examplewindow.cc

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "examplewindow.h"
#include <iostream>

ExampleWindow::ExampleWindow()
: m_VBox(Gtk::ORIENTATION_VERTICAL),
  m_Button_Close("Close")
{
  set_title("Gtk::Entry");

  add(m_VBox);

  m_Entry.set_max_length(50);
  m_Entry.set_text("Hello world");
  m_VBox.pack_start(m_Entry, Gtk::PACK_SHRINK);

  //Change the progress fraction every 0.1 second:
  Glib::signal_timeout().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_timeout), 
    100
  );

  m_Button_Close.signal_clicked().connect( sigc::mem_fun(*this,
              &ExampleWindow::on_button_close) );
  m_VBox.pack_start(m_Button_Close, Gtk::PACK_SHRINK);
  m_Button_Close.set_can_default();
  m_Button_Close.grab_default();

  show_all_children();
}

ExampleWindow::~ExampleWindow()
{
}

bool ExampleWindow::on_timeout()
{
  static double fraction = 0;
  m_Entry.set_progress_fraction(fraction);

  fraction += 0.01;
  if(fraction > 1)
    fraction = 0;

  return true;
}

void ExampleWindow::on_button_close()
{
  hide();
}


main.cc

1
2
3
4
5
6
7
8
9
10
11
12
#include "examplewindow.h"
#include <gtkmm/application.h>

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

  ExampleWindow window;

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


Now I'm waiting for answers. And doing other stuff than coding 'cause it's stressful to wait in front of the computer. Please answer ASAP.

I'm sure you guys are beginner-friendly people rather than those guys at stackoverflow.
Did you include "examplewindow.cc" in your project?
Isn't that it's not a good thing to #include a .cc file?
I #include it and same thing. Still the same error.
No, I did not mean that way.
Move everything in "examplewindow.cc" to "main.cc".
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
ander@Ander:~/C++_Programming/test$ g++ main.cc -o seimple `pkg-config gtkmm-3.0 --cflags --libs`
main.cc: In function ‘int main(int, char**)’:
main.cc:6:10: error: ‘app’ does not name a type
     auto app = Gtk::Application::create(argc, argv, "org.gtkmm.example");
          ^
main.cc:9:12: error: ‘app’ was not declared in this scope
     return app->run(window);
            ^
main.cc: In member function ‘void ExampleWindow::on_button_dialog_clicked()’:
main.cc:75:7: error: ‘cout’ is not a member of ‘std’
       std::cout << "Cancel clicked." << std::endl;
       ^
main.cc:80:7: error: ‘cout’ is not a member of ‘std’
       std::cout << "Unexpected button clicked: " << result << std::endl;
       ^


it gave me this error.
Topic archived. No new replies allowed.