Hello World?

Do you have a question about makefiles, a compiler or IDE you are using and need to know how to set it up for wxWidgets or why it doesn't compile but other IDE's do ? Post your questions here.
Post Reply
tuk1
Earned some good credits
Earned some good credits
Posts: 114
Joined: Sun Oct 08, 2017 9:36 am

Hello World?

Post by tuk1 »

-----------
wxWidgets-3.1.0
VS 2015
Win7 x64
-----------

Following the steps below, I was able to successfully display the example gui 'minimal', included with the wx library:
  • Grab the sources.
    Unpack the sources.
    Open VS IDE.
    Open \build\msw\wx-vc14.sln (adjust as necessary.)
    Go to "Build->Batch Build...", click "Select All", "Build".
    Go drink some coffee or watch TV.
    After the build finishes, open wxWidgets/samples/minimal/minimal_vc9.sln.
    Let MSVC convert the solution to become an appropriate format.
    Build and run the sample
https://stackoverflow.com/questions/379 ... tudio-2015

It then says:
The next step is to copy the samples\minimal folder somewhere and start writing the code. All you will need to do is to change the Include and Lib search path.

So, I attempted to use the 'Hello World' example from the website:

Code: Select all

// wxWidgets "Hello world" Program
// For compilers that support precompilation, includes "wx/wx.h".
#include <wx/wxprec.h>
#ifndef WX_PRECOMP
    #include <wx/wx.h>
#endif
class MyApp: public wxApp
{
public:
    virtual bool OnInit();
};
class MyFrame: public wxFrame
{
public:
    MyFrame();
private:
    void OnHello(wxCommandEvent& event);
    void OnExit(wxCommandEvent& event);
    void OnAbout(wxCommandEvent& event);
};
enum
{
    ID_Hello = 1
};
wxIMPLEMENT_APP(MyApp);
bool MyApp::OnInit()
{
    MyFrame *frame = new MyFrame();
    frame->Show( true );
    return true;
}
MyFrame::MyFrame()
        : wxFrame(NULL, wxID_ANY, "Hello World")
{
    wxMenu *menuFile = new wxMenu;
    menuFile->Append(ID_Hello, "&Hello...\tCtrl-H",
                     "Help string shown in status bar for this menu item");
    menuFile->AppendSeparator();
    menuFile->Append(wxID_EXIT);
    wxMenu *menuHelp = new wxMenu;
    menuHelp->Append(wxID_ABOUT);
    wxMenuBar *menuBar = new wxMenuBar;
    menuBar->Append( menuFile, "&File" );
    menuBar->Append( menuHelp, "&Help" );
    SetMenuBar( menuBar );
    CreateStatusBar();
    SetStatusText( "Welcome to wxWidgets!" );
    Bind(wxEVT_MENU, &MyFrame::OnHello, this, ID_Hello);
    Bind(wxEVT_MENU, &MyFrame::OnAbout, this, wxID_ABOUT);
    Bind(wxEVT_MENU, &MyFrame::OnExit, this, wxID_EXIT);
}
void MyFrame::OnExit(wxCommandEvent& event)
{
    Close( true );
}
void MyFrame::OnAbout(wxCommandEvent& event)
{
    wxMessageBox( "This is a wxWidgets' Hello world sample",
                  "About Hello World", wxOK | wxICON_INFORMATION );
}
void MyFrame::OnHello(wxCommandEvent& event)
{
    wxLogMessage("Hello world from wxWidgets!");
}
http://docs.wxwidgets.org/trunk/overvie ... world.html

The includes in the 'Hello World' code were throwing not found errors but I was able to clear this by adding the wx header directory to the vs project properties:
wxWidgets-3.1.0\include\wx
-----

The trouble now is the following compile error:
Capture.PNG
Capture.PNG (49.39 KiB) Viewed 2266 times
...and, type errors(underlined in red) in the 'Hello World' code:
Capture2.PNG
Capture2.PNG (64.01 KiB) Viewed 2266 times
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Hello World?

Post by PB »

First, do not add the setup.h file to your project properties, this is wrong and just an attempt to work around the real problem..


You did not post the most important information, i.e., the configuration you are trying to build and your compiler and linker paths. Assuming system environment variable WXWIN is set up properly (points to the wxWidgets directory such as c:\wxWidgets), your include directories should look like this

32-bit static debug configuration:

Code: Select all

"$(WXWIN)\lib\vc_lib\mswud";"$(WXWIN)\include"
32-bit static release configuration:

Code: Select all

"$(WXWIN)\lib\vc_lib\mswu";"$(WXWIN)\include"
and so on. Do they? Can file setup.h be located in the matching configuration folder?

BTW, I would suggest reading the official documentation, located in WXWIN/docs/msw/install.txt.
Last edited by PB on Sun Oct 08, 2017 3:52 pm, edited 1 time in total.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Hello World?

Post by doublemax »

Go to "Build->Batch Build...", click "Select All", "Build".
Go drink some coffee or watch TV.
Usually you only need two of all the configurations. Building one takes about 2 minutes on a Quadcore CPU if the files are on an SSD.
The next step is to copy the samples\minimal folder somewhere and start writing the code.
So, I attempted to use the 'Hello World' example from the website:
This is not what the previous statement meant. You should really copy the whole directory (especially the project files) from <wxdir>/samples/minimal/ to another locations and then modify the project.

The projects in the "samples" directory use relative paths for include files and libraries, so if you copy the folder somewhere else, they won't work any more and you need to adjust those paths.

These are:
C/C++ > General > Additional Include Directories
Linker > General > Additional Library Directories
Resources > General > Additional Include Directories

You need to make those changes for all configurations you want to use.
Use the source, Luke!
tuk1
Earned some good credits
Earned some good credits
Posts: 114
Joined: Sun Oct 08, 2017 9:36 am

Re: Hello World?

Post by tuk1 »

This is not what the previous statement meant. You should really copy the whole directory (especially the project files) from <wxdir>/samples/minimal/ to another locations and then modify the project.

The projects in the "samples" directory use relative paths for include files and libraries, so if you copy the folder somewhere else, they won't work any more and you need to adjust those paths.
I want to use other wx code not just the examples included in wx library, If you read the replies they talk about making your own gui projects after getting the sample working.
tuk1
Earned some good credits
Earned some good credits
Posts: 114
Joined: Sun Oct 08, 2017 9:36 am

Re: Hello World?

Post by tuk1 »

PB wrote:First, do not add the setup.h file to your project properties, this is wrong and just an attempt to work around the real problem..

You did not post the most important information, i.e., the configuration you are trying to build and your compiler and linker paths. Assuming system environment variable WXWIN is set up properly (points to the wxWidgets directory such as c:\wxWidgets), your include directories should look like this

32-bit static debug configuration:

Code: Select all

"$(WXWIN)\lib\vc_lib\mswud";"$(WXWIN)\include"
32-bit static release configuration:

Code: Select all

"$(WXWIN)\lib\vc_lib\mswu";"$(WXWIN)\include"
and so on. Do they? Can file setup.h be located in the matching configuration folder?

BTW, I would suggest reading the official documentation, located in WXWIN/docs/msw/install.txt.
I didn't install wx, I followed the SO guide which said just unpack the wx library into a folder so my win os might not have the wx reg info.

However, I have referenced the unpacked include folder which cleared the include errors in Hello World.
Capture.PNG
Capture.PNG (37.91 KiB) Viewed 2257 times
Setup.h is in a folder on it's own:

Code: Select all

D:\CODE\#  wxWidgets\wxWidgets-3.1.0(1)\include\msvc\wx
The main library is here:

Code: Select all

D:\CODE\#  wxWidgets\wxWidgets-3.1.0(1)\include\wx
But, the problem(op pic): #include "wx/setup.h" is located in platform.h ...I don't understand why the library cant find its own files?
---

ps is there an online version of install.txt? ...as the file in the folder is a wall of text written on one line.
wxWidgets(v3.2.2.1) - Vs2022(v143) - Win10(x64) - DialogBlocks(v5.16.5_Unicode)
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Hello World?

Post by PB »

tuk1 wrote:Setup.h is in a folder on it's own:

Code: Select all

D:\CODE\#  wxWidgets\wxWidgets-3.1.0(1)\include\msvc\wx
That is not the setup.h file that is an issue. I meant the configuration (release, debug...) specific one, which is copied after the wxWidgets configuration has been successfully built. E.g., if you plan on using 32-bit static debug library, the file should reside in

Code: Select all

D:\CODE\#  wxWidgets\wxWidgets-3.1.0(1)\lib\vc_lib\mswud\wx
That is why I told you to include the configuration-specific folder before the main wx include folder in my previous post. BTW, I would advise against putting wxWidgets in a folder with spaces in it, it could lead to issues.
tuk1 wrote:ps is there an online version of install.txt? ...as the file in the folder is a wall of text written on one line.
The file can be properly displayed with any decent text editor as well as Notepad shipped with all Windows versions? Anyway, you can view it on the wxWidgets code repository: https://github.com/wxWidgets/wxWidgets/ ... nstall.txt I believe that once you read it, many things become much more clear...
Post Reply