Skip to content

Building on windows

Jefferson González edited this page Dec 27, 2013 · 20 revisions

Requirements

When building with PHP 5.3 - 5.4

When building PHP 5.5

Overall requirements

  • wxWidgets 3.0.0
  • PHP5 Sources
  • wxPHP source code
  • Read the README_MSW

Download and install wxWidgets 3.0.0

  1. Download wxWidgets in one of the compressed formats of your choice

7 Zip or Zip

  1. Enable wxPosScriptDC

On wxWidgets source directory open:

    include\wx\msw\setup.h 
    include\wx\setup_inc.h

then change 'wxUSE_POSTSCRIPT 0' to:

    wxUSE_POSTSCRIPT 1

I'm not really sure but I noticed that changing include\wx\msw\setup.h didn't had any effect on the final setup.h generated for the compiled libraries so just in case I also recommend to modify include\wx\setup_inc.h

  1. Compile wxWidgets

If using Visual C++ 2008, open Windows SDK 6.1 CMD Shell:

    setenv /release /x86 /xp
    cd wxWidgets_Installation_Path
    cd build\msw
    nmake -f makefile.vc BUILD=release

If using Visual C++ 2012, open VS2012 x86 Native Tools Command Prompt:

    cd wxWidgets_Installation_Path
    cd build\msw
    nmake -f makefile.vc BUILD=release
  1. Uncomment or remove some declarations

Linking errors where produced when linking wxphp to wxwidgets from some deprecated methods that seemed to be implemented on log.cpp but strangely enough are producing linking errors.

Note: You should do this after wxWidgets was compiled and before compiling the wxPHP extension.

Fix: Comment out the following declarations/prototypes from the wxwidgets include/wx/log.h

wxLogFormatter::FormatTime(long)const

The line should look like this:

    virtual wxString FormatTime(time_t t) const;

wxLog::DoLog(unsigned long,wchar_t const *,long)

wxLog::DoLog(unsigned long,char const *,long)

The lines should look like these:

    wxDEPRECATED_BUT_USED_INTERNALLY(
        virtual void DoLog(wxLogLevel level, const char *szString, time_t t)
    );

    wxDEPRECATED_BUT_USED_INTERNALLY(
        virtual void DoLog(wxLogLevel level, const wchar_t *wzString, time_t t)
    );

Download and Install PHP sources

NOTE: Compilation has been tested against PHP 5.3 and 5.5 it should work with any 5.3.x - 5.5.x version of php

  1. Download PHP:

To check available versions for download:

http://windows.php.net/download/

  1. Create the directory:

     c:\php-sdk
    
  2. Download PHP 5 binary tools:

http://windows.php.net/downloads/php-sdk/

  1. Extract the binary tools inside the directory c:\php-sdk leaving you with:

     c:\php-sdk\bin
     c:\php-sdk\script
    
  2. Prepare for building

On Visual C++ 2008, open the Windows SDK 6.1 CMD Shell and do the following:

    setenv /release /x86 /xp
    cd c:\php-sdk\
    bin\phpsdk_setvars.bat
    bin\phpsdk_buildtree.bat phpdev

On Visual C++ 2012, open the Windows SDK 6.1 CMD Shell and do the following:

    cd c:\php-sdk\
    bin\phpsdk_setvars.bat
    bin\phpsdk_buildtree.bat phpdev
  1. Extract the php source files and place them on:

     c:\php-sdk\phpdev\vc9\x86\php5.x.x
    
  2. Install additional dependencies (Optional)

On the c:\php-sdk\phpdev\vc9\x86 directory you will see a folder called deps, there you can place additional libraries required to build some of the php extensions which you find for your PHP specific version on http://windows.php.net/downloads/php-sdk/

  1. PHP Source Changes

mode_t is defined on wxWidgets and PHP at the same time which causes a re-declaration conflict to the compiler.

Fix: On TSRM/tsrm_virtual_cwd.h substitute:

    typedef unsigned short mode_t;

with

    #ifndef __WXMSW__
    typedef unsigned short mode_t;
    #endif

wx.rc Needed on php.exe

It seems that some wxWidgets components rely on cursors and icons that need to be embedded on the main application executable, like for example wxStyledTextCtrl. In this case the application executable is php.exe or php-win.exe

Steps to include wx.rc on these executables:

Open: win32/build/template.rc and replace

    #ifdef WANT_LOGO
    0 ICON win32\build\php.ico
    #endif

with

    #ifdef WANT_LOGO
    0 ICON win32\build\php.ico
    #include <wx/msw/wx.rc>
    #endif

in order to only include the wx.rc file when the system is building the php.exe or php-win.exe.

Modify: win32/build/confutils.js and replace all occurences of

    $(RC)

with

    $(RC) /I PATH_TO_WXWIDGETS\\include

where PATH_TO_WXWIDGETS can be C:\\wxWidgets. This is to ensure that the resource compiler fines the file wx.rc.

Important: If this steps are omitted the php executable will crash each time a wxWidgets component that relies on some specific resources is loaded.

  1. Then compile the sources to see if everything is working:

     cd c:\php-sdk\phpdev\vc9\x86\php5.x.x
     buildconf
     configure --disable-all --disable-zts --enable-cli --enable-cli-win32
     nmake
    

Compile wxPHP

Note: Make sure to read the README_MSW for some compilation and linking fixes which are also detailed on this page

  1. Get wxPHP sources:

     git clone git@github.com:wxphp/wxphp.git wxphp
    
  2. Put the source code in the ext folder of your php build folder:

     c:\php-sdk\phpdev\vc9\x86\php5.x.x\ext\wxwidgets
    
  3. On your currently opened development command prompt:

     cd c:\php-sdk\phpdev\vc9\x86\php5.x.x
     nmake clean
     buildconf --force
     configure --disable-all --disable-zts --enable-cli --enable-cli-win32 --with-wxwidgets=C:\wxWidgets_installation_path
     nmake
    

Copy the resulting php_wxwidgets.dll file on the Release directory to the php extensions directory of your current PHP 5 VC9 X86 Non Thread Safety setup. Also don't forget to replace your original php executables with the one produced from this build since these new executables include wxWidgets resources required by some components as describer before on the PHP Source Changes step.

If you want the wxWidget extension to be automatically loaded, add the following lines to the end of your php.ini:

    [PHP_WXWIDGETS]
    extension=php_wxwidgets.dll