## Compiling code using Mingw and wxWidgets on command line Windows 10

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.
Thunderchook
Earned a small fee
Posts: 17
Joined: Wed Feb 01, 2017 9:59 am

### Compiling code using Mingw and wxWidgets on command line Windows 10

Hi,

Successfully compiled/installed wxWidgets with mingw on Windows 10.
Trying to just compile a basic lump of code.

This is what I would use under Ubuntu - it works:
g++ main.cpp main.h simple.cpp simple.h `wx-config --cxxflags --libs` -o simple

Can anyone tell me where to find a tutorial/list/etc of appropriate flags to compile under Windows 10?

Thanks,

Thunderchook.

xaviou
Super wx Problem Solver
Posts: 429
Joined: Mon Aug 21, 2006 3:18 pm
Location: Annecy - France
Contact:

### Re: Compiling code using Mingw and wxWidgets on command line Windows 10

Hi.

The better way to get these flags/parameters is to compile the "minimal" sample that comes with the sources.

If you use the same command line to build the sample than the one used to build the libs, you'll obtain the correct command line to compile and link the sources.

Regards
Xav'
My wxWidgets stuff web page : [email protected]'s wxStuff

ONEEYEMAN
Part Of The Furniture
Posts: 4173
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

### Re: Compiling code using Mingw and wxWidgets on command line Windows 10

Hi,
When you try to compile your own code with MinGW on command line you should use the same compiler option you used when compiled wxWidgets itself.

Thank you.

Manolo
Can't get richer than this
Posts: 712
Joined: Mon Apr 30, 2012 11:07 pm

### Re: Compiling code using Mingw and wxWidgets on command line Windows 10

Compiling your own code on Windows is just a little more tricky than on Linux because of lacking wx-config. But just "a little" and likely for the first time.

One way is to use an already project-file (like samples\minimal\minimal_vc12.sln for MSVC) and change some dirs and names.

For MinGW, the build commands included in samples\minimal\makefile.gcc are the basis of your own compilation. It's hard to read that makefile. A helping trick is to compile "minimal" redirecting its output to a file: mingw32-make -f makefile.gcc >myLog.txt 2>&1 and find there the included dirs (basically include\wx) and required libs. Other samples (AUI, grid, etc) expose other needed libs.

xaviou
Super wx Problem Solver
Posts: 429
Joined: Mon Aug 21, 2006 3:18 pm
Location: Annecy - France
Contact:

### Re: Compiling code using Mingw and wxWidgets on command line Windows 10

Manolo wrote:Compiling your own code on Windows is just a little more tricky than on Linux because of lacking wx-config.
I've build a version of wx-config for Windows (started from CodeLite's sources) :
http://x.psoud.free.fr/?/soft/wxconfig.html

Regards
Xav'
My wxWidgets stuff web page : [email protected]'s wxStuff

Thunderchook
Earned a small fee
Posts: 17
Joined: Wed Feb 01, 2017 9:59 am

### Re: Compiling code using Mingw and wxWidgets on command line Windows 10

Okay, so I tried the exact same line of gmake-32 as I did to compile the wxWidgets library in the "Minimal" sample.
The process completed without error.
No executable.
Am I missing a step?

So, I could be wrong but am I to understand that the whole mingw+wxWidgets combination under Windows is nowhere near as simple as Linux?
I cannot simply type something like:

g++ main.cpp main.h otherfile.cpp. otherfile.h -SOMEFLAG -ANOTHERFLAG=value -o FinishedProduct.exe

and get a working application at the end?

I notice that there is a heavy dependency on make files.
Should I go back to the drawing board and learn to create make files from scratch?

If so, can anyone suggest a good resource for basics of compiling c++ programs using make files (even how to create the make file in the first place!) under Windows?

Thanks,

Thunderchook.

ONEEYEMAN
Part Of The Furniture
Posts: 4173
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

### Re: Compiling code using Mingw and wxWidgets on command line Windows 10

Hi,
Did you add "-o YourExeName.exe" to the compiler line?

What did you use to compile the application? Can you post the exact compiler invocation line?

Thank you.

Thunderchook
Earned a small fee
Posts: 17
Joined: Wed Feb 01, 2017 9:59 am

### Re: Compiling code using Mingw and wxWidgets on command line Windows 10

The command I used to compile the wxWidgets libraries was:

mingw32-make -f makefile.gcc SHARED=1 UNICODE=1 BUILD=release CXXFLAGS="-std=gnu++11"

I was advised to use the same command to compile the basic,"minimal" program in the samples directory, so I used:

mingw32-make -f makefile.gcc SHARED=1 UNICODE=1 BUILD=release CXXFLAGS="-std=gnu++11" -o Minimal.exe

No joy.

I'm surprised that it is harder to do something in Windows than in Linux! Usually, it's the complete opposite!
But, I need to have code run under Windows (nobody I know uses Linux, so no .exe will work on their machine) so I need to see this through.

I'm doing to basic research into using make files, but I figured there would be a way to include wxWidgets libraries at the command line to compile code.

Thanks,

Thunderchook.

PB
Part Of The Furniture
Posts: 2437
Joined: Sun Jan 03, 2010 5:45 pm

### Re: Compiling code using Mingw and wxWidgets on command line Windows 10

When you are using a compiled 3rd party library such as wxWidgets, you need to tell your compiler/linker:
1. Where are the header files needed for declarations.
2. Often also provide necessary defines.
3. Names of the libraries to link with.
4. Where are the libraries from (3) stored.

I have never used wx-config but I believe that it provides the information from above. When you are not using it, you need to provide it by yourself on the command line. This is very impractical and I guess that's why hardly anyone does it and the compilation is done via makefiles or IDEs.

Basically, no matter how seemingly simple your program is, you still need to follow these instructions:
WXWIN/docs/msw/install.txt wrote:Building Applications Using wxWidgets
=====================================

NB: The makefiles and project files provided with wxWidgets samples show which
flags should be used when building applications using wxWidgets so in case
of a problem, e.g. if the instructions here are out of date, you can always
simply copy a makefile or project file from %WXWIN%\samples\minimal or some

Independently of the compiler and make/IDE you are using you must do the
following to use wxWidgets sources under the directory \$WXWIN (notice that
different tool chains refer to environment variables such as WXWIN in
different ways, e.g. MSVC users should use \$(WXWIN) instead of just \$WXWIN):

- compiler
- resource compiler
include paths.
* Define the following symbols for the preprocessor:
- __WXMSW__ to ensure you use the correct wxWidgets port.
- _UNICODE unless you want to use deprecated ANSI build of wxWidgets.
- NDEBUG if you want to build in release mode, i.e. disable asserts.
- WXUSINGDLL if you are using DLL build of wxWidgets.
* If using MSVC 7 only (i.e. not for later versions), also define
wxUSE_RC_MANIFEST=1 and WX_CPU_X86.
* Add \$WXWIN\lib\prefix_lib-or-dll to the libraries path. The prefix depends
on the compiler, by default it is "vc" for MSVC, "gcc" for g++ and so on.
depends on which libraries you use and whether you built wxWidgets in
monolithic or default multlib mode and basically should include all the
relevant libraries from the directory above, e.g. "wxmsw30ud_core.lib
wxbase30ud.lib wxtiffd.lib wxjpegd.lib wxpngd.lib wxzlibd.lib wxregexud.lib
wxexpatd.lib" for a debug build of an application using the core library only
(all wxWidgets applications use the base library).

Microsoft Visual C++ users can simplify the linker setup by prepending
"\$(WXWIN)\include\msvc" to the include path (it must come before the
"\$(WXWIN)\include" part!) and omitting the last step: the required libraries
will be linked in automatically using the "#pragma comment(lib)" feature of
this compiler.

Manolo
Can't get richer than this
Posts: 712
Joined: Mon Apr 30, 2012 11:07 pm

### Re: Compiling code using Mingw and wxWidgets on command line Windows 10

To compile a wxWidgets sample with mingw or TDM:
* cd to samples\somesample
* mingw32-make -f makefile.gcc SHARED=1 UNICODE=1 BUILD=release CXXFLAGS="-std=gnu++11" (these are your flags used to build wx)
Notice there's no '-o minimal.exe' at end. Using a makefile writes it for you.

Thunderchook
Earned a small fee
Posts: 17
Joined: Wed Feb 01, 2017 9:59 am

### Re: Compiling code using Mingw and wxWidgets on command line Windows 10

Okay, so yes, that is one of the commands I had typed in previously.
I tried it again, and it appeared to have completed normally however it still yields no executable.

I ran this in the c:\wxWidgets-3.0.2\Samples\minimal directory on what, I believe to be, the smallest, simplest sample program available.

Still at a loss.

I just want to compile a simple program but it is proving most difficult!
Ordinarily, I would say "Screw it!" and just go back to Linux but I will need to get it going under Windows at some point.

doublemax
Moderator
Posts: 14897
Joined: Fri Apr 21, 2006 8:03 pm
Location: \$FCE2

### Re: Compiling code using Mingw and wxWidgets on command line Windows 10

I tried it again, and it appeared to have completed normally however it still yields no executable.
If there was no error message, there should be an executable. However, the exe will not appear on the same level as the source file. It will be in a subdir which name depends on the configuration. E.g. in "gcc_mswud" or something similar.
Use the source, Luke!

ONEEYEMAN
Part Of The Furniture
Posts: 4173
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

### Re: Compiling code using Mingw and wxWidgets on command line Windows 10

Just do following:

Code: Select all

``````cd /
fiind . -name (program_name)
``````
Or try to search for it in Windows explorer.

Thunderchook
Earned a small fee
Posts: 17
Joined: Wed Feb 01, 2017 9:59 am

### Re: Compiling code using Mingw and wxWidgets on command line Windows 10

Thank you all for your help.
You've all been most helpful and supportive.

But, I'm over it.
I'm gave up and went back to Linux.
I had a fully working compiler in both Code::Blocks and Command Prompt working in less than an hour.
I'll have another go at trying to get it going under Windows when I'm a little more proficient in coding c++, compilers, reading compiler errors and creating/using makefiles in general.
Maybe then it will make a little more sense.
In the meantime, I'm just going to concentrate on building my coding skills.