Author Topic: Linking Errors with 'Hello World' program using wxWidgets - HELP! :)  (Read 21398 times)

Offline Rytz

  • Single posting newcomer
  • *
  • Posts: 9
Having some frustrating linking problems.  It's probably something simple and I'm just completely retarded.

Specs:
OS: Windows XP
IDE: Code::Blocks
Compiler: MinGW32
Library: wxWidgets

I'm having this problem with the 'Hello World' sample project from the help files included with wxWidgets.  I also tried a different 'Hello World' sample from the net for wxWidgets and get the same result.

This is my first time around with the IDE, Compiler, and wxWidgets, so I kind of expected this.  I'm used to using VS for just about everything so I wanted to move away from it.

I'll paste the sample 'HW' code and the linker error code below:

HW Code:
Code
#include <iostream.h>
#include "wx/wx.h"


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


class MyFrame: public wxFrame {
public:
    MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);

    void OnQuit(wxCommandEvent& event);
    void OnAbout(wxCommandEvent& event);
private:
    DECLARE_EVENT_TABLE()};


enum {
    ID_Quit = 1,
    ID_About,};


BEGIN_EVENT_TABLE(MyFrame, wxFrame)
    EVT_MENU(ID_Quit,  MyFrame::OnQuit)
    EVT_MENU(ID_About, MyFrame::OnAbout)
END_EVENT_TABLE()
IMPLEMENT_APP(MyApp)


bool MyApp::OnInit() {
    MyFrame *frame = new MyFrame( "Hello World", wxPoint(50,50), wxSize(450,340) );
    frame->Show( true );
    SetTopWindow( frame );
    return true;}


MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
       : wxFrame((wxFrame *)NULL, -1, title, pos, size) {
    wxMenu *menuFile = new wxMenu;

    menuFile->Append( ID_About, "&About..." );
    menuFile->AppendSeparator();
    menuFile->Append( ID_Quit, "E&xit" );

    wxMenuBar *menuBar = new wxMenuBar;
    menuBar->Append( menuFile, "&File" );

    SetMenuBar( menuBar );

    CreateStatusBar();
    SetStatusText( "Welcome to wxWidgets!" );}


void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) {
    Close( true );}


void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) {
    wxMessageBox( "This is a wxWidgets' Hello world sample",
                  "About Hello World", wxOK | wxICON_INFORMATION );}


Linker Errors:
Code
Compiling: C:\Documents and Settings\Rytz\My Documents\_PROJECTS\CodeBlocks\Test1\test1.cpp
In file included from C:/Program Files/CodeBlocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/c++/3.4.4/backward/iostream.h:31,
                 from C:\Documents and Settings\Rytz\My Documents\_PROJECTS\CodeBlocks\Test1\test1.cpp:1:
C:/Program Files/CodeBlocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/c++/3.4.4/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
Linking console executable: C:\Documents and Settings\Rytz\My Documents\_PROJECTS\CodeBlocks\Test1\test1.exe
C:\Documents and Settings\Rytz\My Documents\_PROJECTS\CodeBlocks\Test1\test1.o:test1.cpp:(.text+0x160): undefined reference to `wxAppConsole::CheckBuildOptions(char const*, char const*)'
C:\Documents and Settings\Rytz\My Documents\_PROJECTS\CodeBlocks\Test1\test1.o:test1.cpp:(.text+0x206): undefined reference to `wxEntry(HINSTANCE__*, HINSTANCE__*, char*, int)'
C:\Documents and Settings\Rytz\My Documents\_PROJECTS\CodeBlocks\Test1\test1.o:test1.cpp:(.text+0x419): undefined reference to `wxFrameNameStr'
C:\Documents and Settings\Rytz\My Documents\_PROJECTS\CodeBlocks\Test1\test1.o:test1.cpp:(.text+0x534): undefined reference to `wxEmptyString'
C:\Documents and Settings\Rytz\My Documents\_PROJECTS\CodeBlocks\Test1\test1.o:test1.cpp:(.text+0x61e): undefined reference to `wxEmptyString'
C:\Documents and Settings\Rytz\My Documents\_PROJECTS\CodeBlocks\Test1\test1.o:test1.cpp:(.text+0x718): undefined reference to `wxMenuBar::wxMenuBar()'
C:\Documents and Settings\Rytz\My Documents\_PROJECTS\CodeBlocks\Test1\test1.o:test1.cpp:(.text+0x7e0): undefined reference to `wxFrameBase::SetMenuBar(wxMenuBar*)'
C:\Documents and Settings\Rytz\My Documents\_PROJECTS\CodeBlocks\Test1\test1.o:test1.cpp:(.text+0x7e5): undefined reference to `wxStatusLineNameStr'
C:\Documents and Settings\Rytz\My Documents\_PROJECTS\CodeBlocks\Test1\test1.o:test1.cpp:(.text+0x825): undefined reference to `wxFrameBase::CreateStatusBar(int, long, int, wxString const&)'
C:\Documents and Settings\Rytz\My Documents\_PROJECTS\CodeBlocks\Test1\test1.o:test1.cpp:(.text+0x895): undefined reference to `wxFrameBase::SetStatusText(wxString const&, int)'
C:\Documents and Settings\Rytz\My Documents\_PROJECTS\CodeBlocks\Test1\test1.o:test1.cpp:(.text+0x97d): undefined reference to `wxFrame::~wxFrame()'
C:\Documents and Settings\Rytz\My Documents\_PROJECTS\CodeBlocks\Test1\test1.o:test1.cpp:(.text+0x9f1): undefined reference to `wxFrameNameStr'
C:\Documents and Settings\Rytz\My Documents\_PROJECTS\CodeBlocks\Test1\test1.o:test1.cpp:(.text+0xb0c): undefined reference to `wxEmptyString'
C:\Documents and Settings\Rytz\My Documents\_PROJECTS\CodeBlocks\Test1\test1.o:test1.cpp:(.text+0xbf6): undefined reference to `wxEmptyString'
C:\Documents and Settings\Rytz\My Documents\_PROJECTS\CodeBlocks\Test1\test1.o:test1.cpp:(.text+0xcf0): undefined reference to `wxMenuBar::wxMenuBar()'
C:\Documents and Settings\Rytz\My Documents\_PROJECTS\CodeBlocks\Test1\test1.o:test1.cpp:(.text+0xdb8): undefined reference to `wxFrameBase::SetMenuBar(wxMenuBar*)'
C:\Documents and Settings\Rytz\My Documents\_PROJECTS\CodeBlocks\Test1\test1.o:test1.cpp:(.text+0xdbd): undefined reference to `wxStatusLineNameStr'
C:\Documents and Settings\Rytz\My Documents\_PROJECTS\CodeBlocks\Test1\test1.o:test1.cpp:(.text+0xdfd): undefined reference to `wxFrameBase::CreateStatusBar(int, long, int, wxString const&)'
C:\Documents and Settings\Rytz\My Documents\_PROJECTS\CodeBlocks\Test1\test1.o:test1.cpp:(.text+0xe6d): undefined reference to `wxFrameBase::SetStatusText(wxString const&, int)'
C:\Documents and Settings\Rytz\My Documents\_PROJECTS\CodeBlocks\Test1\test1.o:test1.cpp:(.text+0xf55): undefined reference to `wxFrame::~wxFrame()'
C:\Documents and Settings\Rytz\My Documents\_PROJECTS\CodeBlocks\Test1\test1.o:test1.cpp:(.text+0xfa5): undefined reference to `wxWindowBase::Close(bool)'
C:\Documents and Settings\Rytz\My Documents\_PROJECTS\CodeBlocks\Test1\test1.o:test1.cpp:(.text+0x1053): undefined reference to `wxMessageBox(wxString const&, wxString const&, long, wxWindow*, int, int)'
C:\Documents and Settings\Rytz\My Documents\_PROJECTS\CodeBlocks\Test1\test1.o:test1.cpp:(.text+0x111b): undefined reference to `wxEventHashTable::wxEventHashTable(wxEventTable const&)'
C:\Documents and Settings\Rytz\My Documents\_PROJECTS\CodeBlocks\Test1\test1.o:test1.cpp:(.text+0x116b): undefined reference to `wxEVT_COMMAND_MENU_SELECTED'
C:\Documents and Settings\Rytz\My Documents\_PROJECTS\CodeBlocks\Test1\test1.o:test1.cpp:(.text+0x11a8): undefined reference to `wxEVT_COMMAND_MENU_SELECTED'
C:\Documents and Settings\Rytz\My Documents\_PROJECTS\CodeBlocks\Test1\test1.o:test1.cpp:(.text+0x11e5): undefined reference to `wxEVT_NULL'
C:\Documents and Settings\Rytz\My Documents\_PROJECTS\CodeBlocks\Test1\test1.o:test1.cpp:(.text+0x122b): undefined reference to `wxEventHashTable::~wxEventHashTable()'
C:\Documents and Settings\Rytz\My Documents\_PROJECTS\CodeBlocks\Test1\test1.o:test1.cpp:(.rdata+0x0): undefined reference to `wxFrame::sm_eventTable'.............[truncated by me]

collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 8 seconds)
0 errors, 1 warnings

So you get the point.  The list goes on to be about 3-4 times that size.

Go easy on me please :).  I'm spoiled by VS .NET and I hate it.  Plus I'm tired of working with MS platforms only.

I apologize if this isn't even Code::Blocks related.  This is just really bugging me.  Any info would be much appreciated.  Thanks :).

sethjackson

  • Guest
Umm are you linking in the wxWidgets libs?

Offline Rytz

  • Single posting newcomer
  • *
  • Posts: 9
Umm are you linking in the wxWidgets libs?

Thanks for the response.  I did put the lib directories for both Code::Blocks and wxWidgets.  Do I need to do add each lib file individually on the linker tab?

georgie

  • Guest
The problem is of course, with the many different directions on how to build wxwidgets, and the resulting different names for the libraries that are created by the build of wxwidgets, that it's no wonder you and many many others are having difficulties in getting something as simple as "hello world" to compile and link.


sethjackson

  • Guest
Umm are you linking in the wxWidgets libs?

Thanks for the response.  I did put the lib directories for both Code::Blocks and wxWidgets.  Do I need to do add each lib file individually on the linker tab?

Yes something like wxmsw26. Look in path_to_wxWidgets\lib\gcc_dll or path_to_wxWidgets\lib\gcc_lib.

Offline Rytz

  • Single posting newcomer
  • *
  • Posts: 9
Thank you very much for the replies!  I will mess around with the config when I get home from work in a few hours.

Offline Rytz

  • Single posting newcomer
  • *
  • Posts: 9
Umm are you linking in the wxWidgets libs?

Thanks for the response.  I did put the lib directories for both Code::Blocks and wxWidgets.  Do I need to do add each lib file individually on the linker tab?

Yes something like wxmsw26. Look in path_to_wxWidgets\lib\gcc_dll or path_to_wxWidgets\lib\gcc_lib.

I tried looking for that file but didn't find it.  Or anything really similar.  I don't have a gcc_dll path either.  I'm guessing based on the responses so far that I need to rebuild wxWidgets?

Offline Defender

  • Multiple posting newcomer
  • *
  • Posts: 49
Yes, if you build wxWidgets correctly, there should be a gcc_dll path with a large DLL called wxmsw26(...).dll and a library called libwxmsw26(u).lib inside.

Good luck  :)

sethjackson

  • Guest
Yes, if you build wxWidgets correctly, there should be a gcc_dll path with a large DLL called wxmsw26(...).dll and a library called libwxmsw26(u).lib inside.

Good luck  :)

It really depends on if you build wx with SHARED=1 or not.... SHARED=1 builds a DLL, the default is SHARED=0 wich builds a static lib......

Offline Defender

  • Multiple posting newcomer
  • *
  • Posts: 49
Yes, if you build wxWidgets correctly, there should be a gcc_dll path with a large DLL called wxmsw26(...).dll and a library called libwxmsw26(u).lib inside.

Good luck  :)

It really depends on if you build wx with SHARED=1 or not.... SHARED=1 builds a DLL, the default is SHARED=0 wich builds a static lib......
I know, but I didn't want to make it so complicated for him  :lol:
Ok, Rytz: look for a gcc_lib and a gcc_dll directory, if you can find neither of them, you should build wxW first.  8)
« Last Edit: May 19, 2006, 05:12:51 pm by Defender »

sethjackson

  • Guest
Re: Linking Errors with 'Hello World' program using wxWidgets - HELP! :)
« Reply #10 on: May 19, 2006, 06:17:25 pm »
Yes, if you build wxWidgets correctly, there should be a gcc_dll path with a large DLL called wxmsw26(...).dll and a library called libwxmsw26(u).lib inside.

Good luck  :)

It really depends on if you build wx with SHARED=1 or not.... SHARED=1 builds a DLL, the default is SHARED=0 wich builds a static lib......
I know, but I didn't want to make it so complicated for him  :lol:
Ok, Rytz: look for a gcc_lib and a gcc_dll directory, if you can find neither of them, you should build wxW first.  8)

Oh. :lol:

Offline Rytz

  • Single posting newcomer
  • *
  • Posts: 9
Re: Linking Errors with 'Hello World' program using wxWidgets - HELP! :)
« Reply #11 on: May 19, 2006, 06:26:19 pm »
Now that you mention the static vs. shared, I think I did the build as static (no DLL's) because I didn't want to rely on DLL's for anything.  I'll rebuild wxWidgets tonight.

Also, since I have a thread open, if I use the install package for CodeBlocks instead of compiling my own version, am I at a huge loss?  Am I at a huge disadvantage for not compiling my own version?  Thanks.

georgie porgie

  • Guest
Re: Linking Errors with 'Hello World' program using wxWidgets - HELP! :)
« Reply #12 on: May 19, 2006, 07:55:50 pm »
No, I wouldn't compile codeblocks unless you plan on doing some development on it.  And if and when you do want to do some development on it, i'd worry about compiling it at that time.


Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Linking Errors with 'Hello World' program using wxWidgets - HELP! :)
« Reply #13 on: May 19, 2006, 09:52:31 pm »
Quote
Also, since I have a thread open, if I use the install package for CodeBlocks instead of compiling my own version, am I at a huge loss?  Am I at a huge disadvantage for not compiling my own version?  Thanks.
Compiling your own is a little bit of a leap off the Lion's head (was that what they called it in Indiana Jones...?) :)

However, it is nowhere near complicated once you have compiled a monolithic wxWidgets (this is about the hardest part of it).

The disadvantages of building your own are that it is scary if you have never done it (although it is more or less pressing one button ;)), and that it takes 3-4 minutes to finish.

The advantages are (besides that it's cool) that you can update at any time, so you don't have to wait until the next nightly build comes out. Also, you can compile using your own favourite compiler flags (for example, I don't know whether or not Lieven builds his nightlies with the crash handler enabled) and if you have subversion on your PC, you'll get accurate revision times in addition to the revision number.
Also, you can apply a patch from the patch tracker if there is an additional feature that is not in the main codebase yet, and you can make your own modifications if you deem them necessary. The nice thing about it is that as long as there are no conflicts, your changes made to the source tree persist when you update to another revision.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

sethjackson

  • Guest
Re: Linking Errors with 'Hello World' program using wxWidgets - HELP! :)
« Reply #14 on: May 19, 2006, 10:27:57 pm »
.....
and if you have subversion on your PC, you'll get accurate revision times in addition to the revision number.

The revision time does not show up in the start here page "()" (assuming that is where the time is supposed to go). I get empty parenthesis. Check out the newest nightly to see what I mean.....
« Last Edit: May 19, 2006, 10:31:53 pm by sethjackson »