Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C++ (http://www.programmingforums.org/forum15.html)
-   -   wxWidgets problem (http://www.programmingforums.org/showthread.php?t=13208)

rwm May 25th, 2007 6:15 AM

wxWidgets problem
 
Hey guys!

Mmm, i just installed wxWidgets 2.8.4 - it's the first time i've used it... im running Fedora 4.

I installed it using:

:

COMPILING USING CONFIGURE
=========================

* The simplest case
-------------------

If you compile wxWidgets on Linux for the first time and don't like to read
install instructions just do (in the base dir):

> ./configure --with-x11
> make
> su <type root password>
> make install
> ldconfig
> exit


all went fine - but when i tried to create this app from this tutorial:

http://www.bzzt.net/~wxwidgets/icpp_wx1.html

it didnt compile - however i could compile the samples included with the wxWidgets package just fine...

i get this error:

:

...
/usr/local/include/wx-2.8/wx/scrolwin.h:55: note:                wxScrollHelper::wxScrollHelper(wxWindow*)
/usr/local/include/wx-2.8/wx/sizer.h: In member function ‘void wxSizerItem::SetMinSize(const wxSize&)’:
/usr/local/include/wx-2.8/wx/sizer.h:285: error: invalid use of undefined type ‘struct wxWindow’
/usr/local/include/wx-2.8/wx/utils.h:51: error: forward declaration of ‘struct wxWindow’
basic.h: At global scope:
basic.h:4: error: expected class-name before ‘{’ token
basic.h:4: warning: ‘class BasicApplication’ has virtual functions but non-virtual destructor
basic.h:9: error: invalid use of undefined type ‘struct wxFrame’
/usr/local/include/wx-2.8/wx/log.h:538: error: forward declaration of ‘struct wxFrame’
basic.cpp: In function ‘wxAppConsole* wxCreateApp()’:
basic.cpp:4: error: cannot convert ‘BasicApplication*’ to ‘wxAppConsole*’ in return
basic.cpp: In function ‘BasicApplication& wxGetApp()’:
basic.cpp:4: error: ‘wxApp’ has not been declared
basic.cpp:4: error: ‘GetInstance’ was not declared in this scope
basic.cpp: In member function ‘virtual bool BasicApplication::OnInit()’:
basic.cpp:9: error: ‘class BasicFrame’ has no member named ‘Show’
basic.cpp:10: error: ‘SetTopWindow’ was not declared in this scope
basic.cpp:12: error: expected ‘;’ before ‘:’ token
basic.cpp:12: error: expected primary-expression before ‘:’ token
basic.cpp:12: error: expected `;' before ‘:’ token
basic.cpp: In constructor ‘BasicFrame::BasicFrame(const wxChar*, int, int, int, int)’:
basic.cpp:16: error: type ‘struct wxFrame’ is not a direct base of ‘BasicFrame’
make: *** [basic.o] Error 1


obviously its not linking - i've set the $LD_LIBRARY_PATH to include /usr/local/lib which is where wxWidgets libraries are located...

i added -I/usr/local/include/wx-2.8/ to get the includes - but then gave more errors on linking.

i didnt play around with the $LIBS variable in the Makefile (i.e. -L/usr/local/lib/) because im not very familiar with linking... the flags are very foreign to me, its actually a little scary!

here is the full code:

:

// basic.h
#ifndef BASIC_H
#define BASIC_H

class BasicApplication : public WxApp {
        public:
                virtual bool OnInit();
};

class BasicFrame : public wxFrame {
        public:
                BasicFrame(const wxChar *title,int xpos,int ypos,int width,int height);
                ~BasicFrame();
};

#endif


:

// basic.cpp
#include <wx/wx.h>
#include "basic.h"

IMPLEMENT_APP(BasicApplication);

bool BasicApplication::OnInit() {
        BasicFrame *frame = new BasicFrame("basic",50,50,450,300);

        frame->Show(TRUE);
        SetTopWindow(frame);

        return TRUE:
}

BasicFrame::BasicFrame(const wxChar *title,int xpos,int ypos,int width,int height)
                        : wxFrame((wxFrame *)NULL,-1,title,wxPoint(xpos,ypos),wxSize(width,height)) {}

BasicFrame::~BasicFrame() {}


:

// basic_resources.rc
#include "wx/msw/wx.rc"


:

// Makefile
PROGRAM = basic
OBJECTS = ${PROGRAM}.o ${PROGRAM}_resources.o
RC = windres.exe
CC = g++

INCLUDES = -I/usr/local/include/wx-2.8/

CCSW1 = --pipe -fvtable-thunks -c -D_X86_=1 -DWIN32 -D_WIN32 -DWINVER=0x0400 -D__WIN95__ \
        -D__GNUWIN32__ -D__WIN32__ -DSTRICT  -D__WXMSW__ -D__WINDOWS__\
        -Wall -fno-pcc-struct-return -O2 -fno-rtti -fno-exceptions 

CCSW2 = --pipe -fvtable-thunks -Wl,--subsystem,windows -mwindows

LIBS  = -lwx -lxpm -lcomctl32 -ladvapi32 -lwsock32 -lole32 -loleaut32 -luuid

RESSW = --include-dir c:/gcc-2.95.2-1/i386-mingw32msvc/include \
        --define __WIN32__ --define __WIN95__ --define __GNUWIN32__

.SUFFIXES: .o .cpp

all:    ${OBJECTS}
        $(CC) -o $(PROGRAM) ${OBJECTS} ${CCSW2} ${LIBS}

.cpp.o:
        $(CC) ${CCSW1} ${INCLUDES} -c -o $@ $<

${PROGRAM}_resources.o:
        $(RC) ${RESSW} ${PROGRAM}.rc $@

.PHONY : clean

clean:
        echo cleaning up
        rm $(OBJECTS)
        rm *.$$$$$$
        rm ${PROGRAM}.exe


i hope someone can help! any response will be much appreciated! :D

dr.p May 25th, 2007 8:11 AM

You need to include wx.h in your header file so that the wx classes are recognizable in that file.

If you get a linker error talking about "duplicate resources," you need to comment out the wx.rc include line.

rwm May 25th, 2007 11:05 AM

mmm - didnt seem to work! :/

ill have a good look at the samples included and see whats missing!

ill post back if im still stuck!

thanks for help! :)

Game_Ender May 26th, 2007 4:09 PM

Lets make this easy on you, when on Linux you should not do X11 you should do wxGTK (that would be --with-gtk). Once you have that done you should use the wx-config tool, not hard code all the options. This means you can build program with this simple command line:
:

g++ myapp.cpp `/usr/local/bin/wx-config --libs --cflags`
This calls the wx-config application and asks it supply the proper cflags and library flags the "``" tell the shell to take that output and replace everything between the "``" with it.

Also you have a lot of "msw" type path and even a windows *.exe file doesn't make much sense on Linux.

rwm May 28th, 2007 3:51 AM

guys i have no idea what im doing here! i always have trouble iwth GUIs they give me a headache all that macro crap and whatnot!

ok - why mustn't i use X11??? i know GTK is another windowing system - but not all distros have it? but they all certainly have X11 right?

mmm, i didnt get a chance to work on this this weekend - gonna try look at it between work, so busy these days :/

Game_Ender May 28th, 2007 10:41 AM

GTK is much better supported and maintained then the port X11. You don't want to run into trouble that is due to bugs in the library. All distros have GTK. GTK is the GUI toolkit used by GIMP, Gaim and the Gnome desktop. Even KDE based distros have GTK because lots of linux apps are written with GTK.

rwm May 28th, 2007 11:03 AM

ok coolio! thanks for the advice man... sure didnt know that stuff! :D


All times are GMT -5. The time now is 2:30 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC