wxFormBuilder code does not compile undefined reference to `MyWindow::MyWindow(wxWindow*)'

Hello all,
as the title suggests, I am unable to compile my wxFormBuilder project. I am new to c++ (last contact is about 10 years ago) and I am trying to reenter gui application development. So, I think this is a newbie question, but perhaps you will help me nevertheless.

The error is:

1
2
3
4
LANG="en_US.UTF-8" g++ `wx-config --version=3.1-gtk3 --cxxflags --libs` main.cpp
/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/ccvKOguT.o: in function `App::OnInit()':
main.cpp:(.text+0xaf): undefined reference to `MyWindow::MyWindow(wxWindow*)'
collect2: Fehler: ld gab 1 als Ende-Status zurück



wxFormBuilder generated code (ui.h):
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
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b3)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////

#pragma once

#include <wx/artprov.h>
#include <wx/xrc/xmlres.h>
#include <wx/string.h>
#include <wx/frame.h>
#include <wx/gdicmn.h>
#include <wx/font.h>
#include <wx/colour.h>
#include <wx/settings.h>

///////////////////////////////////////////////////////////////////////////


///////////////////////////////////////////////////////////////////////////////
/// Class MainWindow
///////////////////////////////////////////////////////////////////////////////
class MainWindow : public wxFrame
{
        private:

        protected:

        public:

                MainWindow( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("Window1"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 500,300 ), long style = wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL );

                ~MainWindow();

};


wxFormBuilder generated code (ui.cpp):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b3)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////

#include "ui.h"

///////////////////////////////////////////////////////////////////////////

MainWindow::MainWindow( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxFrame( parent, id, title, pos, size, style )
{
        this->SetSizeHints( wxDefaultSize, wxDefaultSize );


        this->Centre( wxBOTH );
}

MainWindow::~MainWindow()
{
}


wxFormBuilder classes for inheritance MyWindow.h:

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

#ifndef __MyWindow__
#define __MyWindow__

/**
@file
Subclass of MainWindow, which is generated by wxFormBuilder.
*/

#include "ui.h"

//// end generated include

/** Implementing MainWindow */
class MyWindow : public MainWindow
{
        public:
                /** Constructor */
                MyWindow( wxWindow* parent );
        //// end generated class members


};

#endif // __MyWindow__ 



wxFormBuilder classes for inheritance MyWindow.cpp:
1
2
3
4
5
6
7
8
#include "MyWindow.h"

MyWindow::MyWindow( wxWindow* parent )
:
MainWindow( parent )
{

}


and finally my main.cpp:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <wx/wxprec.h>
#ifndef WX_PRECOMP
    #include <wx/wx.h>
#endif
#include "./ui/MyWindow.h"

class App : public wxApp { public: virtual bool OnInit(); };

wxIMPLEMENT_APP(App);

bool App::OnInit() 
{
    MyWindow *w = new MyWindow(NULL);
    
    return true;
}


Sorry, but I can't figure out what I am missing here or doing wrong. Perhaps someone has a hint ?

Big thank you in advance!

Greetings
michael
I don't see any evidence that you are compiling ui.cpp, MyWindow.cpp, or linking them when building the final executable.
Last edited on
Are MyWindow.cpp and ui.cpp part of the project?

> LANG="en_US.UTF-8" g++ `wx-config --version=3.1-gtk3 --cxxflags --libs` main.cpp
You should be seeing something like this for each .cpp file.

If you're not, then those source files are not being compiled.
T H A N K Y O U ! you both.

What a silly mistake!


 
LANG="en_US.UTF-8" g++ ui/ui.h ui/ui.cpp ui/MyWindow.h ui/MyWindow.cpp main.cpp `wx-config --version=3.1-gtk3 --cxxflags --libs`


Did the trick.
Last edited on
Topic archived. No new replies allowed.