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

From WxWiki
Jump to navigation Jump to search
(Pure MinGW section seems out of date, added a more up to date section)
(Both sections describe pure MinGW compilation (without MSYS) moved to Compiling wxWidgets with MinGW and Using Makefiles to compile wxWidgets)
Line 1: Line 1:
= Using the Makefiles that come with wxWidgets (version 1) =
+
== Installing an compiling ==
== Install MinGW ==
 
Please follow the steps described in [[Installing MinGW under Window]].
 
== Configure your build ==
 
At this point you might want to edit ''\include\wx\msw\setup.h''
 
== Build the library ==
 
Open the '''command prompt''' (Start > Run... > cmd).
 
Change the directory to the '''build\msw''' folder. For example:
 
<source lang="dos">
 
CD wx\\wx288\\build\\msw
 
</source>
 
 
 
Clean up the source:
 
<source lang="dos">
 
mingw32-make -f makefile.gcc MONOLITHIC=1 SHARED=1 UNICODE=1 BUILD=release clean
 
</source>
 
 
 
Then, compile the library:
 
<source lang="dos">
 
mingw32-make -f makefile.gcc MONOLITHIC=1 SHARED=1 UNICODE=1 BUILD=release
 
</source>
 
 
 
=== See also ===
 
[http://wiki.codeblocks.org/index.php?title=WxWindowsQuickRef Code::Block's WxWindowsQuickRef]<br>
 
[http://wiki.codeblocks.org/index.php?title=Compiling_wxWidgets_2.8.6_to_develop_Code::Blocks_(MSW) Compiling wxWidgets 2.8.6 to develop Code::Blocks (MSW)]
 
 
 
= Using the Makefiles that come with wxWidgets (version 2) =
 
{{SectionOutOfDate}}
 
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].
 
* The following packages are required:
 
**gcc-core
 
**gcc-g++
 
**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==
 
 
 
* 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.
Line 156: Line 73:
 
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.
 
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.
 
%%
 
%%
 +
 +
== See Also ==
 +
[[Installing WxWin MinGW]]
 +
 +
== External Links ==
 +
An alternate how-to is available at http://max.berger.name/howto/wxWidgets/wxWidgets_MinGW.jsp

Revision as of 19:38, 26 August 2008

Installing an 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
  • 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).
    I'm not an expert, but I believe the following two steps should be ignored.
    You would therefore run ./configure instead of ../configure in the third step.
    I also found that I needed to replace "`dirname $$f`" with "$$f" in a whole bunch
    of Makefile.in before running "./configure". I was using wxWidgets 2.8.8, and believe
    this is a bug.
    • 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)
    • make your wx ($ 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).

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.

Problems with MinGW 3.2

%3.2 If having problems with "include/wx/msw/missing.h", 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 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 & 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 > 3 has this problem or whether it's just me. %%

See Also

Installing WxWin MinGW

External Links

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