Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Compiling FreeTDS under Windows: Difference between revisions

From MoodleDocs
m (Added download links for freetds 0.82 and php 5.2.6)
No edit summary
 
(17 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{Work in progress}}__NOTOC__
==Requirements==
==Requirements==


* MSVC 6.0 (Microsoft Visual C++ 6.0) with Service Packs installed.
* MSVC 6.0 (Microsoft Visual C++ 6.0) with Service Packs installed.
* FreeTDS (tested with [http://www.ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-0.82.tar.gz version 0.82]).
* February 2003 Platform SDK (must be February 2003, last supported platform SDK for VC6) [see [[FebruaryPlatformSDK]]]
* PHP source files (tested with [http://www.php.net/get/php-5.2.6.tar.gz/from/a/mirror version 5.2.6])
* FreeTDS (tested with [http://ibiblio.org/pub/Linux/ALPHA/freetds/old/0.82/freetds-patched.tgz version 0.82+official patchset] - updated 2011-09-06).
* PHP source files (tested with [http://www.php.net/get/php-5.3.5.tar.gz/from/a/mirror version 5.3.5])
* These packages (non-debug):
* These packages (non-debug):
** From http://pecl2.php.net/downloads/php-windows-builds/php-libs/ :
** From http://pecl2.php.net/downloads/php-windows-builds/php-libs/ :
Line 13: Line 12:
*** libiconv
*** libiconv
*** libxml
*** libxml
*** libxlst
*** libxslt
*** zlib
*** zlib


Line 20: Line 19:
* Create c:\dev
* Create c:\dev
* Create c:\dev\php-build
* Create c:\dev\php-build
* Uncompress all the packages listed in requirements and PHP into c:\dev\php-build (replacing all when uncompressing).
* Uncompress all the packages listed in requirements and PHP into c:\dev\php-build (replacing all when uncompressing). Make sure to extract the bin, lib, include folders without any top level directory contained within the archive.
* Copy uncompressed freetds folder to C:\dev\php-build (rename it to, simply, "freetds").
* Copy uncompressed [http://ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-patched.tgz freetds] folder to C:\dev\php-build (rename it to, simply, "freetds").
* Open the C:\dev\php-build\freetds\win32\msvc6\FreeTDS.dsw Project Workspace (it's really important to get this Workspace and not any of the individual projects!).
* Open the C:\dev\php-build\freetds\win32\msvc6\FreeTDS.dsw Project Workspace (it's really important to get this Workspace and not any of the individual projects!).
* Select the "dblib files" project and then Build->Rebuild All, this should en with one dblib.lib library into C:\dev\php-build\freetd\win32\msvc6\db_Release
* In the "Build" menu, set the "Active Configuration" to  "dblib - Win32 Release" and then, in the same menu, "Rebuild All". This should end with one dblib.lib library into C:\dev\php-build\freetd\win32\msvc6\db_Release
* Copy dblib.lib to C:\dev\php-build\lib
* Copy dblib.lib to C:\dev\php-build\lib
* Start CMD
* Start CMD
Line 34: Line 33:
* Execute this:
* Execute this:
** buildconf
** buildconf
** cscript /nologo configure.js --disable-all --disable-ipv6 --enable-zts (--disable-zts)  --with-dblib=shared --enable-object-out-dir=c:\dev --with-extra-includes=c:\dev\php-build\freetds\include;c:\dev\php-build\freetds\win32
** cscript /nologo configure.js --disable-all --disable-ipv6 --enable-cli --enable-zts (--disable-zts)  --with-dblib=shared --enable-object-out-dir=c:\dev --with-extra-includes=c:\dev\php-build\freetds\include;c:\dev\php-build\freetds\win32
** nmake
** nmake
* You should end with one C:\dev\Release_TS for the --enable-zts (or C:\dev\Release for the --disable-zts alternative)  dir, with your compiled FreeTDS PHP module ready at the root level of that dir.
* You should end with one C:\dev\Release_TS for the --enable-zts (or C:\dev\Release for the --disable-zts alternative)  dir, with your compiled FreeTDS PHP module ready at the root level of that dir. CLI was passed as a build option above because as of PHP v5.3.x you must specify one SAPI modile to get a build.


==Notes==
==Notes==
Line 46: Line 45:
* And MDL-11810 has a related discussion.
* And MDL-11810 has a related discussion.


[[Category:Installation]]
==Building FreeTDS for PHP 5.5.x (VC11)==
Build process
Building PHP 5.5.1 with FreeTDS 0.91.89 for moodle 2.5.1 under x86 vc11
 
Requirements:
* Visual C 11 (Visual Studio 2012) (Free-to-download Express version OK) (Windows SDK not required)
* Current stable PHP source (http://php.net/downloads.php)
* Current stable FreeTDS source (ftp://ftp.freetds.org/pub/freetds/stable/)
* Most recent binary tools (http://windows.php.net/downloads/php-sdk/)
* PHP dependencies (http://windows.php.net/downloads/php-sdk/)
 
(At time of writing... the binary tools haven't been updated since 2011... but its OK)
 
Setup PHP environment by following guide: (follow the steps carefully)
https://wiki.php.net/internals/windows/stepbystepbuild
- In step 8, bin\phpsdk_buildtree.bat may not create a vc11 folder so I just copy the vc9 and rename.
 
Ensure you can build PHP under this created environment using:
  buildconf
  configure --disable-all --enable-cli
  nmake
 
Building FreeTDS
Discussion with FreeTDS source maintainers [http://permalink.gmane.org/gmane.comp.db.tds.freetds/11009 here] suggests that the visual studio project/solution/workspace files are not maintained. You may get mixed results from these files. Visual Studio 2012 is very good at upgrading solution files from previous versions.
 
One method:
* If you have used the suggested paths then put the freetds source files here: C:\php-sdk\phpdev\vc11\x86\php-5.5.1-src\freetds
* Open the freetds\win32\msvc6\FreeTDS.dsw Project Workspace. Allow visual studio to upgrade.
* In the configuration manager, set the "Active Solution Configuration" to Release and platform to Win32
(you may not need to build all of the projects in the solution)
This should end with a dblib.lib library in one of the Release folders of freetds\win32\msvc6\
* Copy dblib.lib and libTDS.lib to C:\php-sdk\phpdev\vc11\x86\deps\lib
 
If when attempting to build php_dblib.lib from source you get linking errors, it is probably because you are missing some source files in the projects/solutions. Doing a file search in the src folder for the symbol (without the preceding underscore) should highlight where the function definition comes from. Add the file to the project that won’t compile. Rinse and Repeat.
freetds\src\tds and freetds\src\replacements are good places to look.
 
If when attempting to build php_dblib.lib from source you get  fatal error C1083: Cannot open include file: 'inttypes.h', you must get the required C99 header from https://code.google.com/p/msinttypes/downloads/list and extract inttypes.h to freetds\include.
 
If you would like to build x64 versions of the lib, simply create a new release platform for dblib and libTDS in the Configuration Manager, for x64. You can copy the config from Win32, although you will get some build time warnings due to OutputFile being incorrectly set (you may ignore those).
 
When php_dblib.lib is compilied and in the php lib folder in your build environment, the last thing is to configure the makefile appropriately. (You may also need to compile libTDS.lib from FreeTDS - I had to.).
 
I used a number of different configurations while testing. This one worked:
  configure --disable-all --disable-zts --enable-cli --with-dblib=shared
    --with-extra-includes=C:\php-sdk\phpdev\vc11\x86\php-5.5.1-src\freetds\include;C:\php-sdk\phpdev\vc11\x86\php-5.5.1-src\freetds\win32
 
Check the output from the configure call in case there any skipped dependencies. (like dblib!)
 
“--with-dblib=shared” is the key line for actually telling make to create an external dll file and not just compile the functionality directly into PHP core.
 
If while using nmake an unresolved external symbol linker error is reported: e.g. “error LNK2019: unresolved external symbol _tdsdump_log referenced in function _dblib_add_connection” you may need to add libTDS.lib to the libs statement in makefile and rerun make. http://enyby.blogspot.co.uk/2013/01/eliminate-errors-compile-freetds-on.html. I had to do this.
Sample LIBS declaration:
  LIBS=libTDS.lib kernel32.lib ole32.lib user32.lib advapi32.lib shell32.lib ws2_32.lib Dnsapi.lib
 
Use “--enable-zts” or --disable-zts” for thread safety as mentioned.
 
Then when php_dblib.dll is created put it in the ext folder in your run time environment and enable the extension in your php.ini and you’re good to go!
 
==See also==
*In the [https://moodle.org/mod/forum/discuss.php?d=232844#p1012743 FreeTDS php_dblib.dll for PHP 5.5] discussion on the Using Moodle forum David Aylmer describes how to compile the php_dblib.dll binary for Windows.


[[Category:XMLDB]]
[[Category:XMLDB]]
[[Category:DB]]

Latest revision as of 09:28, 10 November 2013

Requirements

Build Steps

  • Create c:\dev
  • Create c:\dev\php-build
  • Uncompress all the packages listed in requirements and PHP into c:\dev\php-build (replacing all when uncompressing). Make sure to extract the bin, lib, include folders without any top level directory contained within the archive.
  • Copy uncompressed freetds folder to C:\dev\php-build (rename it to, simply, "freetds").
  • Open the C:\dev\php-build\freetds\win32\msvc6\FreeTDS.dsw Project Workspace (it's really important to get this Workspace and not any of the individual projects!).
  • In the "Build" menu, set the "Active Configuration" to "dblib - Win32 Release" and then, in the same menu, "Rebuild All". This should end with one dblib.lib library into C:\dev\php-build\freetd\win32\msvc6\db_Release
  • Copy dblib.lib to C:\dev\php-build\lib
  • Start CMD
  • Create one C:\dev\prepare4php.bat file with contents below and execute it:
@set PATH=C:\dev\php-build\bin;%PATH%
@set INCLUDE=C:\dev\php-build\include;%INCLUDE%
@set LIB=C:\dev\php-build\lib;%LIB%
@set BISON_SIMPLE=C:\dev\php-build\bin\bison.simple
  • Continue in CMD and change dir to C:\dev\php-build\php-x-x-x
  • Execute this:
    • buildconf
    • cscript /nologo configure.js --disable-all --disable-ipv6 --enable-cli --enable-zts (--disable-zts) --with-dblib=shared --enable-object-out-dir=c:\dev --with-extra-includes=c:\dev\php-build\freetds\include;c:\dev\php-build\freetds\win32
    • nmake
  • You should end with one C:\dev\Release_TS for the --enable-zts (or C:\dev\Release for the --disable-zts alternative) dir, with your compiled FreeTDS PHP module ready at the root level of that dir. CLI was passed as a build option above because as of PHP v5.3.x you must specify one SAPI modile to get a build.

Notes

  • By using --enable-zts or --disable-zts you'll end with different thread safe/no safe versions of the extension. Use them depending of your environment thread safety.
  • If you one use PHP 5.2 version to build the lib, the extensions generated are expected to work against any PHP 5.2.x version (but not against other releases of PHP, like 5.1 or 5.3).
  • MSVC 6.0 is required because it's the official tool used to build PHP binary distributions. It seems that, with PHP 5.3 they will start using MSVC 9 or so... corresponding extensions should use the same.
  • Feel free to fix and improve this document. TIA!
  • For any comment related to this, please use MDL-14725 in the Moodle Tracker.
  • And MDL-11810 has a related discussion.

Building FreeTDS for PHP 5.5.x (VC11)

Build process Building PHP 5.5.1 with FreeTDS 0.91.89 for moodle 2.5.1 under x86 vc11

Requirements:

(At time of writing... the binary tools haven't been updated since 2011... but its OK)

Setup PHP environment by following guide: (follow the steps carefully) https://wiki.php.net/internals/windows/stepbystepbuild - In step 8, bin\phpsdk_buildtree.bat may not create a vc11 folder so I just copy the vc9 and rename.

Ensure you can build PHP under this created environment using:

 buildconf
 configure --disable-all --enable-cli
 nmake

Building FreeTDS Discussion with FreeTDS source maintainers here suggests that the visual studio project/solution/workspace files are not maintained. You may get mixed results from these files. Visual Studio 2012 is very good at upgrading solution files from previous versions.

One method:

  • If you have used the suggested paths then put the freetds source files here: C:\php-sdk\phpdev\vc11\x86\php-5.5.1-src\freetds
  • Open the freetds\win32\msvc6\FreeTDS.dsw Project Workspace. Allow visual studio to upgrade.
  • In the configuration manager, set the "Active Solution Configuration" to Release and platform to Win32

(you may not need to build all of the projects in the solution) This should end with a dblib.lib library in one of the Release folders of freetds\win32\msvc6\

  • Copy dblib.lib and libTDS.lib to C:\php-sdk\phpdev\vc11\x86\deps\lib

If when attempting to build php_dblib.lib from source you get linking errors, it is probably because you are missing some source files in the projects/solutions. Doing a file search in the src folder for the symbol (without the preceding underscore) should highlight where the function definition comes from. Add the file to the project that won’t compile. Rinse and Repeat. freetds\src\tds and freetds\src\replacements are good places to look.

If when attempting to build php_dblib.lib from source you get fatal error C1083: Cannot open include file: 'inttypes.h', you must get the required C99 header from https://code.google.com/p/msinttypes/downloads/list and extract inttypes.h to freetds\include.

If you would like to build x64 versions of the lib, simply create a new release platform for dblib and libTDS in the Configuration Manager, for x64. You can copy the config from Win32, although you will get some build time warnings due to OutputFile being incorrectly set (you may ignore those).

When php_dblib.lib is compilied and in the php lib folder in your build environment, the last thing is to configure the makefile appropriately. (You may also need to compile libTDS.lib from FreeTDS - I had to.).

I used a number of different configurations while testing. This one worked:

 configure --disable-all --disable-zts --enable-cli --with-dblib=shared
   --with-extra-includes=C:\php-sdk\phpdev\vc11\x86\php-5.5.1-src\freetds\include;C:\php-sdk\phpdev\vc11\x86\php-5.5.1-src\freetds\win32

Check the output from the configure call in case there any skipped dependencies. (like dblib!)

“--with-dblib=shared” is the key line for actually telling make to create an external dll file and not just compile the functionality directly into PHP core.

If while using nmake an unresolved external symbol linker error is reported: e.g. “error LNK2019: unresolved external symbol _tdsdump_log referenced in function _dblib_add_connection” you may need to add libTDS.lib to the libs statement in makefile and rerun make. http://enyby.blogspot.co.uk/2013/01/eliminate-errors-compile-freetds-on.html. I had to do this. Sample LIBS declaration:

 LIBS=libTDS.lib kernel32.lib ole32.lib user32.lib advapi32.lib shell32.lib ws2_32.lib Dnsapi.lib 

Use “--enable-zts” or --disable-zts” for thread safety as mentioned.

Then when php_dblib.dll is created put it in the ext folder in your run time environment and enable the extension in your php.ini and you’re good to go!

See also