Difference between revisions of "Compiling wxWidgets with MSYS-MinGW"

From WxWiki
Jump to navigation Jump to search
(Suggesting a possible correction, and think I've found a bug in makefiles)
(11 intermediate revisions by 7 users not shown)
Line 1: Line 1:
= Using the Makefiles that come with wxWidgets =  
+
== Note ==
The following instructions are based on [http://wxforum.shadonet.com/viewtopic.php?t=11457 this forum post].
 
==Setting up MinGW==
 
  
* Download the latest version of MinGW from [http://sourceforge.net/project/showfiles.php?group_id=2435 its SourceForge page].
+
<div style="background-color: #f5f5f5; padding: 10px; border: 1px solid #000; margin-bottom: 1.13em;">'''NOTE:'''
* The following packages are required:
+
It may be worthwhile to try [[Compiling wxWidgets with MinGW]] first. MSYS adds an extra layer of complexity on top of
**gcc-core
+
MinGW that you may not necessarily be interested in, at least in the beginning.
**gcc-g++
+
</div>
**mingw-runtime
 
**binutils
 
**mingw32
 
**w32api
 
* You can download and unzip these manually, or use the automated installer.
 
* After installation your MinGW directory should contain the subdirectories: "bin", "doc", "include", "info", "lib", "libexec", "man" and "mingw32".
 
* To use MinGW from the windows command shell, various environment variables must be set. The easiest method to do this is to create a batch script.
 
** Copy the following code into a text file and save it as "ConfigureMinGW.bat".
 
** If you installed MinGW to a location other than the default location "C:\MinGW" substitute that for "C:\MinGW". If your path has spaces in it, surround it with double quotes.
 
<source lang="dos">
 
@echo off
 
set path=C:\\MinGW\\bin;%PATH%
 
set LIBRARY_PATH=C:\\MinGW\\lib
 
set C_INCLUDE_PATH=C:\\MinGW\\include
 
set CPLUS_INCLUDE_PATH=C:\\MinGW\\include\\c++\\3.4.5;C:\\MinGW\\include\\c++\\3.4.5\\backward;C:\\MinGW\\include\\c++\\mingw32;C:\\MinGW\\include
 
</source>
 
* Open a command shell with the "Command Prompt" shortcut from the "Accessories" menu and run your batch script by entering its path.
 
** Alternatively you can create a shortcut that opens a command shell and runs the script automatically. Copy your script to the MinGW folder and create a new shortcut giving the following as the "location".  
 
<source lang="dos">
 
cmd /K C:\\MinGW\\ConfigureMinGW.bat
 
</source>
 
* Test your MinGW console with the command "gcc -v". If you are shown some information on the version of the GCC, you are successfully running the compiler.
 
  
==Compiling the wxWidgets Libraries==
+
== Installing and compiling ==
 
 
* Download and install the wxWidgets package.
 
 
 
* Configure according to your requirements, the file "config.gcc" in the directory "build\msw" in your wxWidgets folder. For flags, 0 means "disabled" and 1 means "enabled".
 
** For example, to enable unicode support, change the line "UNICODE = 0" to "UNICODE = 1".
 
 
 
* Set up a command shell configured to use MinGW as described above.
 
 
 
* Change directory to the directory "build\msw" in your wxWidgets folder using the cd command.
 
** For example, if you installed wxWidgets to "C:\wxWidgets":
 
<source lang="dos">
 
cd C:\\wxWidgets\\build\\msw
 
</source>
 
 
 
* If you are using Windows XP, you must now start a unix-like shell such as "sh" or "bash". The reason is that cmd.exe (the native Windows command processor) will interpret several commands such as "mkdir" as being ''internal'' commands, which get preference over programs such as "mkdir.exe". The makefile expects "mkdir" to behave in the unix way, otherwise you will get strange error messages. By starting "sh" or "bash", the behaviour of "cmd.exe" won't interfere.
 
<source lang="dos">
 
bash
 
</source>
 
 
 
* Compile wxWidgets with the following command.
 
<source lang="dos">
 
mingw32-make -f makefile.gcc
 
</source>
 
 
 
= Compiling wxWidgets with MSYS/MinGW =
 
  
 
MSYS/MinGW provide a very minimal unix-like environment for Windows, not requiring Cygwin.
 
MSYS/MinGW provide a very minimal unix-like environment for Windows, not requiring Cygwin.
  
 
* First, install MinGW from http://www.mingw.org/download.shtml. If you&#39;re using Dev-C++, this was probably already done for you.
 
* First, install MinGW from http://www.mingw.org/download.shtml. If you&#39;re using Dev-C++, this was probably already done for you.
* Download MSYS from http://www.mingw.org/download.shtml
+
* Download MSYS from http://www.mingw.org/download.shtml (NOTE: Please Download&Install The MinGW-5.1.4.EXE Version In The Automated MinGW Section To Skip All Post Install Steps!)
 
* Install it by running the installer application.
 
* Install it by running the installer application.
 
** During the post-install procedure, you&#39;ll be asked where MinGW is installed. This is the directory containing the <tt>bin/</tt> directory with MinGW files. So if the location of mingw is <tt>C:/Dev-Cpp/bin</tt> or <tt>C:/MinGW/bin</tt>, be sure to only give the <tt>C:/Dev-Cpp</tt> or <tt>C:/MinGW</tt> portion. The postinstall script only gives you one shot at this so try to get it right the first time. Note the forward slashes. Don't worry if you make a mistake; just go to the <tt>postinstall</tt> folder and run <tt>pi.bat</tt> to start over again.
 
** During the post-install procedure, you&#39;ll be asked where MinGW is installed. This is the directory containing the <tt>bin/</tt> directory with MinGW files. So if the location of mingw is <tt>C:/Dev-Cpp/bin</tt> or <tt>C:/MinGW/bin</tt>, be sure to only give the <tt>C:/Dev-Cpp</tt> or <tt>C:/MinGW</tt> portion. The postinstall script only gives you one shot at this so try to get it right the first time. Note the forward slashes. Don't worry if you make a mistake; just go to the <tt>postinstall</tt> folder and run <tt>pi.bat</tt> to start over again.
Line 81: Line 32:
 
* Open an MSYS shell by clicking on the Msys icon.
 
* Open an MSYS shell by clicking on the Msys icon.
 
** change to the directory you installed the wx source to (<tt>$ cd c:wx</tt>).
 
** change to the directory you installed the wx source to (<tt>$ cd c:wx</tt>).
    I&#39;m not an expert, but I believe the following two steps should be ignored.
+
<big>The following two commands set up a build directory for your MinGW installation.  
    You would therefore run ./configure instead of ../configure in the third step.
+
This allows you to use the same source tree for multiple, separate builds of wxWidgets.
    I also found that I needed to replace "`dirname $$f`" with "$$f" in a whole bunch
+
You can skip this step, but it will result in the tree being "infected" by Makefiles
    of Makefile.in before running "./configure". I was using wxWidgets 2.8.8, and believe
+
specific to this build.</big>
    this is a bug.
 
 
** create a new build directory (<tt>$ mkdir msw-debug</tt>) call it what you like.
 
** create a new build directory (<tt>$ mkdir msw-debug</tt>) call it what you like.
 
** enter that directory (<tt>$ cd msw-debug</tt>).
 
** enter that directory (<tt>$ cd msw-debug</tt>).
** run configure to &#39;configure&#39; your custom built wxWidgets.  Don&#39;t forget to add your special flags for anything else you want to turn on or off. (<tt>$ ../configure --disable-shared --enable-debug</tt>)
+
** run configure to &#39;configure&#39; your custom built wxWidgets.  Don&#39;t forget to add your special flags for anything else you want to turn on or off. (<tt>$ ../configure --disable-shared --enable-debug</tt>) [[WxWidgets_Build_Configurations]]
** make your wx (<tt>$ make</tt>).
+
    Note: If you had skipped making a separate build directory, you would need to use
** install it into MSYS.  This will be helpful for running the &#39;wx-config&#39; script later (<tt>$ make install</tt>).
+
    ./configure instead of ../configure
 +
** Compile/make your wxWidgets build (<tt>$ make</tt>).
 +
** Install it into MSYS.  This will be helpful for running the &#39;wx-config&#39; script later (<tt>$ make install</tt>).
 
** test your build.  If you see a windows application open up, your wxWidgets has built correctly (<tt>$ cd samples/minimal; make &amp;&amp; minimal.exe</tt>).
 
** test your build.  If you see a windows application open up, your wxWidgets has built correctly (<tt>$ cd samples/minimal; make &amp;&amp; minimal.exe</tt>).
  
== Problems with MinGW 5.1.3 ==
+
== MinGW Version-Specific Issues ==
 +
=== Problems with MinGW 5.1.3 ===
  
 
I ran into a problem where the configure script kept outputting the error:
 
I ran into a problem where the configure script kept outputting the error:
Line 105: Line 58:
 
Maybe that's obvious for some people, but it took me about a day to figure that one out.
 
Maybe that's obvious for some people, but it took me about a day to figure that one out.
  
== Problems with MinGW 3.2 ==
+
== See Also ==
 
+
[[Compiling wxWidgets with MinGW]]
%3.2
 
If having problems with &quot;include/wx/msw/missing.h&quot;, try replacing with the version in [[Cvs]].
 
%%
 
 
 
== Problems with MinGW 3.1 ==
 
 
 
%3.1
 
(thanks to Abhijeet Bhonge for this):
 
To build under mingw 3.1 you would have to do following:
 
       
 
msw/dialup.cpp, Line 860:
 
    put (void*) cast in front of wxRasDialFunc
 
       
 
msw/fontenum.cpp, Line 161:
 
    change wxFONTENUMPROC cast to FONTENUMPROC
 
 
 
common/dynlib.cpp, Line 332:
 
    put (void*) cast in front of call to wxDllGetSymbol()
 
  
This should compile everything properly. If you get strange missing references while linking samples, especially about
+
== External Links ==
wxDataObject, you may also have to add -D__GNUC__=3 to OPTIONS in line 102 in src/makeg95.env. (It seems that the gcc 3.1 compiler is not setting this macro correctly &amp; as a result some code is not included in the compiled library.) In case gcc complains of duplicate definition, remove this. I am not sure whether every installation of gcc &gt; 3 has this problem or whether it&#39;s just me.
+
An alternate how-to is available at http://max.berger.name/howto/wxWidgets/wxWidgets_MinGW.jsp
%%
 

Revision as of 13:18, 24 October 2015

Note

NOTE:

It may be worthwhile to try Compiling wxWidgets with MinGW first. MSYS adds an extra layer of complexity on top of MinGW that you may not necessarily be interested in, at least in the beginning.

Installing and compiling

MSYS/MinGW provide a very minimal unix-like environment for Windows, not requiring Cygwin.

  • First, install MinGW from http://www.mingw.org/download.shtml. If you're using Dev-C++, this was probably already done for you.
  • Download MSYS from http://www.mingw.org/download.shtml (NOTE: Please Download&Install The MinGW-5.1.4.EXE Version In The Automated MinGW Section To Skip All Post Install Steps!)
  • Install it by running the installer application.
    • During the post-install procedure, you'll be asked where MinGW is installed. This is the directory containing the bin/ directory with MinGW files. So if the location of mingw is C:/Dev-Cpp/bin or C:/MinGW/bin, be sure to only give the C:/Dev-Cpp or C:/MinGW portion. The postinstall script only gives you one shot at this so try to get it right the first time. Note the forward slashes. Don't worry if you make a mistake; just go to the postinstall folder and run pi.bat to start over again.
    • If you didn't install MinGW in the root directory the installer will fail to find it. In that case you have to manually tell MSYS where to find MinGW. Go to c:\msys\1.0\etc (change the path to suit your installation) and create a new text file. Open it and add the following line:
    c:/mingw /mingw
Replace c:/mingw with your path. In my case it becomes:
    C:/MinGWStudio/MinGW /mingw
Note the forward slashes!
  • Rename the file to fstab (with no file extension). If you have file extensions hidden (the Windows default) then you have to turn them on. In Windows explorer go to Tools->folder options. Click on the view tab and turn off 'hide extensions for known file types'
  • If you haven't set up your paths, now is a good time to do it. Here is how you do it in Windows XP. Right click on My Computer then select Properties. Click on the advanced tab then the 'environment variables' button. In system variables, look for a variable called path and double click on it. Add the following to the beginning of the value:
    c:\mingw\bin;c:\msys\1.0\bin;
You will probably have to change these values to suit your installation. For instance mine is
    C:\MinGWStudio\MinGW;c:\msys\1.0\bin;
Note the back slashes! Don't delete the existing paths unless you know what you are doing. Make sure MSYS is after the MinGW path. To achieve this in Windows 98 and ME, go to Start/Run and type msconfig. There is a tab called Environment where you can modify the paths and other variables.
  • Download the wxWidgets source from http://www.wxwidgets.org/downld2.htm . Find a version relevant to you (I prefer the non-setup version).
  • Extract the file to somewhere helpful (C:\wx seems like a good choice, or maybe C:\wx241, or likewise).
  • Open an MSYS shell by clicking on the Msys icon.
    • change to the directory you installed the wx source to ($ cd c:wx).

The following two commands set up a build directory for your MinGW installation. This allows you to use the same source tree for multiple, separate builds of wxWidgets. You can skip this step, but it will result in the tree being "infected" by Makefiles specific to this build.

    • create a new build directory ($ mkdir msw-debug) call it what you like.
    • enter that directory ($ cd msw-debug).
    • run configure to 'configure' your custom built wxWidgets. Don't forget to add your special flags for anything else you want to turn on or off. ($ ../configure --disable-shared --enable-debug) WxWidgets_Build_Configurations
    Note: If you had skipped making a separate build directory, you would need to use
    ./configure instead of ../configure 
    • Compile/make your wxWidgets build ($ make).
    • Install it into MSYS. This will be helpful for running the 'wx-config' script later ($ make install).
    • test your build. If you see a windows application open up, your wxWidgets has built correctly ($ cd samples/minimal; make && minimal.exe).

MinGW Version-Specific Issues

Problems with MinGW 5.1.3

I ran into a problem where the configure script kept outputting the error:

    configure: error: cannot guess build type; you must specify one

I fixed it by executing:

    $ ../configure --build=x86-winnt-mingw32
    or, to remove dependencies:
    $ ../configure --build=x86-winnt-mingw32 --disable-shared --disable-threads

Maybe that's obvious for some people, but it took me about a day to figure that one out.

See Also

Compiling wxWidgets with MinGW

External Links

An alternate how-to is available at http://max.berger.name/howto/wxWidgets/wxWidgets_MinGW.jsp