Can't compile wxWidgets with Mingw32

Hello, I am new to the forum, and pretty new to programming as well. I have been using wxWidgets with Python but recently wanted to learn C++. I am running Windows XP Pro.

I've installed wxWidgets and am using Mingw32 for my compiler. I'm having a lot of trouble. Here is the command I have been using to compile:
c++ sample.cpp -o sample

I get the following error:
1
2
wx/wx.h: No such file or directory
wx/sizer.h: No such file or directory


I tried adding WXWIN environment variable with no effect. So I started telling the compiler where wxWidgets was installed:
c++ sample.cpp -B C:/Env/wxMSW-2.8.9 -o sample

Apparently with this the compiler found wxWidgets, but is still giving me errors. Too many errors to paste in here. Here is part of what prints out:
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
C:\DOCUME~1\Jordan\LOCALS~1\Temp/ccqUKUd3.o:sample.cpp:(.text$_ZN12wxAppConsole2
2SetInitializerFunctionEPFPS_vE[wxAppConsole::SetInitializerFunction(wxAppConsol
e* (*)())]+0x7): undefined reference to `wxAppConsole::ms_appInitFn'
C:\DOCUME~1\Jordan\LOCALS~1\Temp/ccqUKUd3.o:sample.cpp:(.text$_ZN12wxWindowBase1
8SetInitialBestSizeERK6wxSize[wxWindowBase::SetInitialBestSize(wxSize const&)]+0
x14): undefined reference to `wxWindowBase::SetInitialSize(wxSize const&)'
C:\DOCUME~1\Jordan\LOCALS~1\Temp/ccqUKUd3.o:sample.cpp:(.text$_ZNK12wxWindowBase
20GetDefaultAttributesEv[wxWindowBase::GetDefaultAttributes() const]+0x1d): unde
fined reference to `wxWindowBase::GetClassDefaultAttributes(wxWindowVariant)'
C:\DOCUME~1\Jordan\LOCALS~1\Temp/ccqUKUd3.o:sample.cpp:(.text$_ZNK12wxWindowBase
10HasCaptureEv[wxWindowBase::HasCapture() const]+0x7): undefined reference to `w
xWindowBase::GetCapture()'
C:\DOCUME~1\Jordan\LOCALS~1\Temp/ccqUKUd3.o:sample.cpp:(.text$_ZN8wxObjectaSERKS
_[wxObject::operator=(wxObject const&)]+0x1c): undefined reference to `wxObject:
:Ref(wxObject const&)'
C:\DOCUME~1\Jordan\LOCALS~1\Temp/ccqUKUd3.o:sample.cpp:(.text$_ZN12wxStringBase4
InitEv[wxStringBase::Init()]+0x7): undefined reference to `wxEmptyString'
C:\DOCUME~1\Jordan\LOCALS~1\Temp/ccqUKUd3.o:sample.cpp:(.text$_ZN8wxStringaSERKS
_[wxString::operator=(wxString const&)]+0x14): undefined reference to `wxStringB
ase::operator=(wxStringBase const&)'
C:\DOCUME~1\Jordan\LOCALS~1\Temp/ccqUKUd3.o:sample.cpp:(.text$_ZN20wxThreadHelpe
rThreadD1Ev[wxThreadHelperThread::~wxThreadHelperThread()]+0x16): undefined refe
rence to `wxThread::~wxThread()'
C:\DOCUME~1\Jordan\LOCALS~1\Temp/ccqUKUd3.o:sample.cpp:(.text$_ZN20wxThreadHelpe
rThreadD0Ev[wxThreadHelperThread::~wxThreadHelperThread()]+0x16): undefined refe
rence to `wxThread::~wxThread()'
C:\DOCUME~1\Jordan\LOCALS~1\Temp/ccqUKUd3.o:sample.cpp:(.text$_ZN13BasicDrawPane
D1Ev[BasicDrawPane::~BasicDrawPane()]+0x16): undefined reference to `wxPanel::~w
xPanel()'
C:\DOCUME~1\Jordan\LOCALS~1\Temp/ccqUKUd3.o:sample.cpp:(.text$_ZN13BasicDrawPane
D0Ev[BasicDrawPane::~BasicDrawPane()]+0x16): undefined reference to `wxPanel::~w
xPanel()'
C:\DOCUME~1\Jordan\LOCALS~1\Temp/ccqUKUd3.o:sample.cpp:(.text$_ZN5MyAppD1Ev[MyAp
p::~MyApp()]+0x16): undefined reference to `wxApp::~wxApp()'
C:\DOCUME~1\Jordan\LOCALS~1\Temp/ccqUKUd3.o:sample.cpp:(.text$_ZN5MyAppD0Ev[MyAp
p::~MyApp()]+0x16): undefined reference to `wxApp::~wxApp()'
collect2: ld returned 1 exit status 


Does anyone know what I am doing wrong?
Last edited on
To use a library in C++ you need at least two things and possibly a third one: the headers, the static library, and maybe a dynamic library that is only used at run time if at all.

It seems your compiler knows where the headers are, but you still need to link the static libraries. In Windows, these have .lib extension. gcc uses the -l option to link static libraries.
Okay, I'm not sure where to find the static library so I tried the following:

c++ sample.cpp -B C:/Env/wxMSW-2.8.9 -l C:/Env/wxMSW-2.8.9 -o sample

Now it doesn't give me a bunch of lines of output. It gives me the following:

1
2
cannot find -lC:/Env/wxMSW-2.8.9
collect2: ld returned 1 exit status


Also, is there a way to permanently add a directory to Mingw32's search path so that I don't have to type in -B every time I compile?
Last edited on
-l only takes a library name. To add a search path to a library, use the -L option, but keep in mind that it doesn't search recursively.

Did you think of doing a search for "*.lib"?
I'm getting a bunch of link errors like the following:

[Linker error] undefined reference to `wxFrameNameStr'


I'm using Dev-C++ with Mingw32 now.
Last edited on
I think I've made some progress, but can't get past the following errors. Does anybody know what is wrong?

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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
C:\Documents and Settings\Jordan\My Documents\Development\C++\Practise>c++ wx2.cpp -o wx -B C:/Env/wxMSW-2.8.9
wx2.cpp:1:19: warning: extra tokens at end of #include directive
In file included from C:/Env/wxMSW-2.8.9/include/wx/defs.h:21,
                 from C:/Env/wxMSW-2.8.9/include/wx/wx.h:15,
                 from wx2.cpp:1:
C:/Env/wxMSW-2.8.9/include/wx/platform.h:196:22: wx/setup.h: No such file or dir
ectory
In file included from C:/Env/wxMSW-2.8.9/include/wx/platform.h:293,
                 from C:/Env/wxMSW-2.8.9/include/wx/defs.h:21,
                 from C:/Env/wxMSW-2.8.9/include/wx/wx.h:15,
                 from wx2.cpp:1:
C:/Env/wxMSW-2.8.9/include/wx/chkconf.h:103:9: #error "wxUSE_DYNLIB_CLASS must b
e defined."
C:/Env/wxMSW-2.8.9/include/wx/chkconf.h:111:9: #error "wxUSE_EXCEPTIONS must be
defined."
C:/Env/wxMSW-2.8.9/include/wx/chkconf.h:119:9: #error "wxUSE_FILESYSTEM must be
defined."
C:/Env/wxMSW-2.8.9/include/wx/chkconf.h:127:9: #error "wxUSE_FS_ARCHIVE must be
defined."
C:/Env/wxMSW-2.8.9/include/wx/chkconf.h:140:9: #error "wxUSE_DYNAMIC_LOADER must
 be defined."
C:/Env/wxMSW-2.8.9/include/wx/chkconf.h:148:9: #error "wxUSE_LOG must be defined
."
C:/Env/wxMSW-2.8.9/include/wx/chkconf.h:156:9: #error "wxUSE_LONGLONG must be de
fined."
C:/Env/wxMSW-2.8.9/include/wx/chkconf.h:164:9: #error "wxUSE_MIMETYPE must be de
fined."
C:/Env/wxMSW-2.8.9/include/wx/chkconf.h:180:9: #error "wxUSE_PRINTF_POS_PARAMS m
ust be defined."
C:/Env/wxMSW-2.8.9/include/wx/chkconf.h:188:9: #error "wxUSE_PROTOCOL must be de
fined."
C:/Env/wxMSW-2.8.9/include/wx/chkconf.h:230:9: #error "wxUSE_REGEX must be defin
ed."
C:/Env/wxMSW-2.8.9/include/wx/chkconf.h:238:9: #error "wxUSE_STDPATHS must be de
fined."
C:/Env/wxMSW-2.8.9/include/wx/chkconf.h:246:9: #error "wxUSE_XML must be defined
."
C:/Env/wxMSW-2.8.9/include/wx/chkconf.h:254:9: #error "wxUSE_SOCKETS must be def
ined."
C:/Env/wxMSW-2.8.9/include/wx/chkconf.h:262:9: #error "wxUSE_STREAMS must be def
ined."
C:/Env/wxMSW-2.8.9/include/wx/chkconf.h:270:9: #error "wxUSE_STOPWATCH must be d
efined."
C:/Env/wxMSW-2.8.9/include/wx/chkconf.h:278:9: #error "wxUSE_TEXTBUFFER must be
defined."
C:/Env/wxMSW-2.8.9/include/wx/chkconf.h:286:9: #error "wxUSE_TEXTFILE must be de
fined."
C:/Env/wxMSW-2.8.9/include/wx/chkconf.h:302:9: #error "wxUSE_URL must be defined
."
C:/Env/wxMSW-2.8.9/include/wx/chkconf.h:310:9: #error "wxUSE_VARIANT must be def
ined."
C:/Env/wxMSW-2.8.9/include/wx/chkconf.h:330:9: #error "wxUSE_ABOUTDLG must be de
fined."
C:/Env/wxMSW-2.8.9/include/wx/chkconf.h:338:9: #error "wxUSE_ACCEL must be defin
ed."
C:/Env/wxMSW-2.8.9/include/wx/chkconf.h:346:9: #error "wxUSE_ANIMATIONCTRL must
be defined."
C:/Env/wxMSW-2.8.9/include/wx/chkconf.h:354:9: #error "wxUSE_BITMAPCOMBOBOX must
 be defined."
C:/Env/wxMSW-2.8.9/include/wx/chkconf.h:362:9: #error "wxUSE_BMPBUTTON must be d
efined."

......(edited to fit length restriction)......

C:/Env/wxMSW-2.8.9/include/wx/chkconf.h:856:9: #error "wxUSE_SPLITTER must be de
fined."
C:/Env/wxMSW-2.8.9/include/wx/chkconf.h:864:9: #error "wxUSE_STATBMP must be def
ined."
C:/Env/wxMSW-2.8.9/include/wx/chkconf.h:872:9: #error "wxUSE_STATBOX must be def
ined."
C:/Env/wxMSW-2.8.9/include/wx/chkconf.h:880:9: #error "wxUSE_STATLINE must be de
fined."
C:/Env/wxMSW-2.8.9/include/wx/chkconf.h:888:9: #error "wxUSE_STATTEXT must be de
fined."
C:/Env/wxMSW-2.8.9/include/wx/chkconf.h:896:9: #error "wxUSE_STATUSBAR must be d
efined."
C:/Env/wxMSW-2.8.9/include/wx/chkconf.h:904:9: #error "wxUSE_TAB_DIALOG must be
defined."
C:/Env/wxMSW-2.8.9/include/wx/chkconf.h:912:9: #error "wxUSE_TEXTCTRL must be de
fined."
C:/Env/wxMSW-2.8.9/include/wx/chkconf.h:920:9: #error "wxUSE_TIPWINDOW must be d
efined."
C:/Env/wxMSW-2.8.9/include/wx/chkconf.h:928:9: #error "wxUSE_TOOLBAR must be def
ined."
C:/Env/wxMSW-2.8.9/include/wx/chkconf.h:936:9: #error "wxUSE_TOOLTIPS must be de
fined."
C:/Env/wxMSW-2.8.9/include/wx/chkconf.h:944:9: #error "wxUSE_TREECTRL must be de
fined."
C:/Env/wxMSW-2.8.9/include/wx/chkconf.h:952:9: #error "wxUSE_VALIDATORS must be
defined."
C:/Env/wxMSW-2.8.9/include/wx/chkconf.h:960:9: #error "wxUSE_WXHTML_HELP must be
 defined."
C:/Env/wxMSW-2.8.9/include/wx/chkconf.h:968:9: #error "wxUSE_XRC must be defined
."
C:/Env/wxMSW-2.8.9/include/wx/chkconf.h:1765:9: #error "wxMessageBox is always n
eeded"
In file included from C:/Env/wxMSW-2.8.9/include/wx/region.h:222,
                 from C:/Env/wxMSW-2.8.9/include/wx/window.h:26,
                 from C:/Env/wxMSW-2.8.9/include/wx/wx.h:36,
                 from wx2.cpp:1:
C:/Env/wxMSW-2.8.9/include/wx/msw/region.h: In constructor `wxRegion::wxRegion(c
onst wxBitmap&, const wxColour&, int)':
C:/Env/wxMSW-2.8.9/include/wx/msw/region.h:31: error: no matching function for c
all to `wxRegion::Union(const wxBitmap&, const wxColour&, int&)'
C:/Env/wxMSW-2.8.9/include/wx/region.h:128: note: candidates are: bool wxRegionB
ase::Union(wxCoord, wxCoord, wxCoord, wxCoord)
C:/Env/wxMSW-2.8.9/include/wx/region.h:130: note:                 bool wxRegionB
ase::Union(const wxRect&)
C:/Env/wxMSW-2.8.9/include/wx/region.h:132: note:                 bool wxRegionB
ase::Union(const wxRegion&)
In file included from wx2.cpp:1:
C:/Env/wxMSW-2.8.9/include/wx/wx.h:105:306: warning: no newline at end of file 
Topic archived. No new replies allowed.