Oh, I'm halfway there.....

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
liowan
Knows some wx things
Knows some wx things
Posts: 34
Joined: Tue Feb 08, 2022 8:57 pm

Oh, I'm halfway there.....

Post by liowan »

Okay, I'm halfway there! I'm running on Windows 10 - 64 bit system. I've finally managed to compile thw wxWidgets library from source for 64-bit code. BUT I have not been able to get it to work generating 32-bit code. Help!

Moving on, how can I load an icon from an icone file?
User avatar
doublemax
Moderator
Moderator
Posts: 19102
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Oh, I'm halfway there.....

Post by doublemax »

liowan wrote: Sat Sep 24, 2022 3:08 am I've finally managed to compile thw wxWidgets library from source for 64-bit code. BUT I have not been able to get it to work generating 32-bit code.
Compiler, IDE? If you were using the command line, which command did you use?
Moving on, how can I load an icon from an icone file?
By using the appropriate constructor: https://docs.wxwidgets.org/trunk/classw ... b724ae0543
Use the source, Luke!
liowan
Knows some wx things
Knows some wx things
Posts: 34
Joined: Tue Feb 08, 2022 8:57 pm

Re: Oh, I'm halfway there.....

Post by liowan »

With all due respect sir, I asked how to do something. I don't need you to tell me just to look at the documentation. I've already looked at the documentation! Unfortunately, there is a major flaw within the documentation - as good as it is, they don't show you an example of how to properly use the functions! I've tried it unsuccessfully. Looking at the documentation doesn't show me what or how to do it!
liowan
Knows some wx things
Knows some wx things
Posts: 34
Joined: Tue Feb 08, 2022 8:57 pm

Re: Oh, I'm halfway there.....

Post by liowan »

On the other topic, I'm using Red Panda Dev C++ w/MinGW GCC 11.2.0 64-Bit, and Embarcadero Dev C++6.3 w/TDM GCC 10.3.0 64-Bit IDEs.
As I said, 64 bit compiles and runs without any issues. Compiling for 32 bit won't work.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7449
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Oh, I'm halfway there.....

Post by ONEEYEMAN »

Hi,
What command did you use to build 32-bit library?

Thank you.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7449
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Oh, I'm halfway there.....

Post by ONEEYEMAN »

Hi,
And for you icon issue - please show how exactly did you tried it?

Thank you.
liowan
Knows some wx things
Knows some wx things
Posts: 34
Joined: Tue Feb 08, 2022 8:57 pm

Re: Oh, I'm halfway there.....

Post by liowan »

//cMain.cpp

cMain::cMain() : wxMDIParentFrame(nullptr, wxID_ANY, "Minimal Application", wxPoint(30, 30), wxSize(900, 600))
{
// Set the frame icon
wxBitmap *icon = new wxBitmap();
icon->LoadFile("STL22.ico");

// Create a menu bar
wxMenu *fileMenu = new wxMenu;
// The "About" item should be in the help menu
wxMenu *helpMenu = new wxMenu;
helpMenu->Append(wxID_ABOUT, wxT("&About...\tF1"),wxT("Show about dialog"));
fileMenu->Append(wxID_EXIT, wxT("E&xit\tAlt-X"),wxT("Quit this program"));
// Now append the freshly created menu to the menu bar...
wxMenuBar *menuBar = new wxMenuBar();
menuBar->Append(fileMenu, wxT("&File"));
menuBar->Append(helpMenu, wxT("&Help"));
// ... and attach this menu bar to the frame
SetMenuBar(menuBar);
// Create a status bar just for fun
CreateStatusBar(2);
SetStatusText("Welcome to wxWidgets!");
}
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7449
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Oh, I'm halfway there.....

Post by ONEEYEMAN »

Hi,
What happen when you use this code?
Also - I don't see an "icon" variable being used anywhere after the call to LoadIcon()...

Thank you.
liowan
Knows some wx things
Knows some wx things
Posts: 34
Joined: Tue Feb 08, 2022 8:57 pm

Re: Oh, I'm halfway there.....

Post by liowan »

I compiled the library via batch file buildgcc_d_r.bat:

echo off
cls

mingw32-make -fmakefile.gcc clean
mingw32-make -fmakefile.gcc BUILD=debug CFG=-m32 UNICODE=0
mingw32-make -fmakefile.gcc BUILD=release CFG=-m32 UNICODE=0

:done
User avatar
doublemax
Moderator
Moderator
Posts: 19102
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Oh, I'm halfway there.....

Post by doublemax »

Code: Select all

wxTopLevelWindow::SetIcon( const wxIcon &icon )	
... takes a wxIcon as parameter, but you're loading a wxBitmap. And, as ONEEYEMAN already mentioned, the SetIcon call is missing.

Code: Select all

mingw32-make -fmakefile.gcc clean
mingw32-make -fmakefile.gcc BUILD=debug CFG=-m32 UNICODE=0
mingw32-make -fmakefile.gcc BUILD=release CFG=-m32 UNICODE=0 
Not all 64bit compilers support 32 bit builds. Double check if your compiler supports it.
Use the source, Luke!
liowan
Knows some wx things
Knows some wx things
Posts: 34
Joined: Tue Feb 08, 2022 8:57 pm

Re: Oh, I'm halfway there.....

Post by liowan »

"What happen when you use this code?"

A message box: "Minimal Error" , Can't load bitmap 'STL22.ico' from resources. Check .rc file.
liowan
Knows some wx things
Knows some wx things
Posts: 34
Joined: Tue Feb 08, 2022 8:57 pm

Re: Oh, I'm halfway there.....

Post by liowan »

On the icon issue...

Now that you've told me what I'm not doing, [-o< how about showing me what I should be doing with a code example???
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7449
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Oh, I'm halfway there.....

Post by ONEEYEMAN »

Hi,
What is inside your rc file?

Thank you.
xamidi
Earned a small fee
Earned a small fee
Posts: 12
Joined: Sun Mar 13, 2022 1:30 am

Re: Oh, I'm halfway there.....

Post by xamidi »

liowan wrote: Sun Sep 25, 2022 11:56 pm "What happen when you use this code?"

A message box: "Minimal Error" , Can't load bitmap 'STL22.ico' from resources. Check .rc file.
Your code seems compilant, but there seems to be an issue with your building process.
Apparently, you are trying to link a 64-bit resource file into a 32-bit application, but it cannot work since the formats are incompatible. (Or you simply do not have a resource file?)

First, I do not use TDM compiler since it creates binaries that are incompatible with most of my dependencies, so instead I'm using the MSVCRT-based WinLibs MinGW-w64 GCC compiler – most recent binaries GCC 12.2.0 (64-bit ; 32-bit). [or GCC 12.2.0 UCRT (64-bit ; 32-bit) if you are linking with UCRT]

What works for me is creating the resource files (`icon.res` and `icon_x64.res`) using the 32-bit and 64-bit compiler versions, respectively, by commands
set GCC_HOME_32=<path to `mingw32` directory of 32-bit GCC>
set GCC_HOME_64=<path to `mingw64` directory of 64-bit GCC>
set WX_HOME=<path to `wxWidgets` directory>
%GCC_HOME_32%/bin/windres icon.rc -O coff -I%WX_HOME%/include -o icon.res
%GCC_HOME_64%/bin/windres icon.rc -O coff -I%WX_HOME%/include -o icon_x64.res --target=pe-x86-64
(e.g. via `.bat` file) with `icon.rc` being in the same directory as your `icon.ico` and containing
aaaa_icon ICON "icon.ico"

#include <wx/msw/wx.rc>
and then when linking using
%GCC_HOME_32%/bin/g++ -o <name>.exe "<relative path to icons>/icon.res" <all other linker arguments>
or
%GCC_HOME_64%/bin/g++ -o <name>.exe "<relative path to icons>/icon_x64.res" <all other linker arguments>
depending on the targeted CPU bus width.

If you want your code to set your icon to the frame, you should then also replace

Code: Select all

wxBitmap *icon = new wxBitmap();
icon->LoadFile("STL22.ico");
by

Code: Select all

SetIcon(wxICON(aaaa_icon));
in your code.
Post Reply