Using wxWidgets with g++

I am trying to do some GUI with c++ using wxWidgets.
I download the deb package libwxgtk2.8-dev with apt-get and installed it.
But when i try to compile a wxWidget application with g++, a bunch of errors shows up.
It says it couldn't find wx/wx.h, and many other errors like undefined variables.

I guess i need to do some setting up to get it up running, but i don't know what to do. I've searched the web and tried a couple of things but in vain.

Hope someone can help me. Thanks.
You might need to make sure that g++ can fild the headers when it tries to compile (though if you installed the deb package I would've thought it would do that automatically?)

Are you using any IDE? IDEs often have options where you can specify directories to look in for headers and libs and things. If you're not, then I haven't a clue.
closed account (S6k9GNh0)
I actually haven't been able to code with wx. I don't think it's a bug and it's probably something I'm doing wrong but my wx is placed under /usr/include/wx-2.8/wx/ which creates the problem of including headers. I could simply have it as an include directory which helps with version control on the library. Anyways, yours should be under /usr/include/wx-2.8/wx. To have the headers include themselves correctly, you have to use /usr/include/wx-2.8 as a search directory. Just add -I/usr/include/wx-2.8 and it should fix it...if you programmed and included correctly.
Last edited on
Hello computerquip.
I tried the include option as you said but it did not work. I searched for the include folder just to reassure myself i had it, and i found 2 of them:
/usr/local/include/wx-2.8/wx
/usr/include/wx-2.8/wx

Why are there two of them?

The tutorial that i am following to get started with wxWidgets instructs to compile the files like below. I have included the errors that are resulting, if that might throw some light.
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
g++ *.cpp *.h 'wx-config --cxxflags --libs' -o simple

g++: wx-config --cxxflags --libs: No such file or directory
In file included from main.cpp:1:
main.h:1:19: error: wx/wx.h: No such file or directory
In file included from main.cpp:1:
main.h:4: error: expected class-name before ‘{’ token
In file included from main.cpp:2:
simple.h:4: error: expected class-name before ‘{’ token
simple.h:6: error: expected ‘,’ or ‘...’ before ‘&’ token
simple.h:6: error: ISO C++ forbids declaration of ‘wxString’ with no type
main.cpp:6: error: expected constructor, destructor, or type conversion before ‘bool’
In file included from simple.cpp:1:
simple.h:1:19: error: wx/wx.h: No such file or directory
In file included from simple.cpp:1:
simple.h:4: error: expected class-name before ‘{’ token
simple.h:6: error: expected ‘,’ or ‘...’ before ‘&’ token
simple.h:6: error: ISO C++ forbids declaration of ‘wxString’ with no type
simple.cpp:3: error: expected ‘,’ or ‘...’ before ‘&’ token
simple.cpp:3: error: ISO C++ forbids declaration of ‘wxString’ with no type
simple.cpp: In constructor ‘Simple::Simple(int)’:
simple.cpp:4: error: class ‘Simple’ does not have any field named ‘wxFrame’
simple.cpp:4: error: ‘NULL’ was not declared in this scope
simple.cpp:4: error: ‘wxID_ANY’ was not declared in this scope
simple.cpp:4: error: ‘title’ was not declared in this scope
simple.cpp:4: error: ‘wxDefaultPosition’ was not declared in this scope
simple.cpp:4: error: ‘wxSize’ was not declared in this scope
simple.cpp:6: error: ‘Centre’ was not declared in this scope
main.h:1:19: error: wx/wx.h: No such file or directory
main.h:4: error: expected class-name before ‘{’ token
simple.h:1:19: error: wx/wx.h: No such file or directory
simple.h:4: error: expected class-name before ‘{’ token
simple.h:6: error: expected ‘,’ or ‘...’ before ‘&’ token
simple.h:6: error: ISO C++ forbids declaration of ‘wxString’ with no type
Hey guys i just figured it out...as it always happens with me it was a stupid error:

I was using the 'inverted comma' for the wx-config options.
 
g++ *.cpp *.h 'wx-config --cxxflags --libs' -o simple


should have been a 'backtick' like this:
 
g++ *.cpp *.h `wx-config --cxxflags --libs` -o simple


I got the little application compiled: the hello world window finally showed up...pheewwww

But nevertheless i need to get my head clear on why there are two include folders on my system.
Topic archived. No new replies allowed.