[Qgis-developer] DBMS support for Win32
Benjamin Ducke
benjamin.ducke at ufg.uni-kiel.de
Tue Dec 11 03:58:42 EST 2007
FWIW, I have attached all my notes on how to get support for
SQLite, MySQL, PostgreSQL and ODBC into GDAL and GRASS using MinGW.
I don't know whether all of this is optimal, but it works
for me.
If you find anything wrong or missing in the instructions, please
let me know.
Benjamin
--
Benjamin Ducke, M.A.
Archäoinformatik
(Archaeoinformation Science)
Institut für Ur- und Frühgeschichte
(Inst. of Prehistoric and Historic Archaeology)
Christian-Albrechts-Universität zu Kiel
Johanna-Mestorf-Straße 2-6
D 24098 Kiel
Germany
Tel.: ++49 (0)431 880-3378 / -3379
Fax : ++49 (0)431 880-7300
www.uni-kiel.de/ufg
-------------- next part --------------
1. COMPILING DBMS DRIVERS
**** ODBC ****
ODBC support is part of the standard Win32 functionality. A recent version of MinGW's Win32 API should have the necessary header file sql.h. In addition, you need to copy over odbc32.dll to a location where the MSYS shell and the GRASS configure script can see it. On a Windows 2000 system, the library we need is located in C:\WINNT\system32. On XP it is in C:\Windows\system32.
You also need to rename the library to odbc.dll so the GRASS and GDAL configure scripts will detect it. E.g., on a Windows 2000 system, do:
cp /c/WINNT/system32/odbc32.dll /usr/lib/odbc.dll
cp /c/WINNT/system32/odbc32.dll /usr/lib/odbcinst.dll
Note: In order to correctly parse the declarations in the odbc header files (sqltype.h, etc.), the file /mingw/include/windows.h needs to be included in every source file that uses ODBC function calls (especially important for GRASS ODBC support: see notes in ).
Note: Windows' own odbc32.dll is not free software and cannot be re-distributed freely! This should not be necessary, however, as every Windows installation should come with a copy of it. To make sure you do not accidentally re-distribute a copy, you may want to delete odbc.dll from /usr/lib after you have finished linking your software to it.
**** PostgreSQL 8.2.5 ****
Download the file postgresql-8.2.5.tar.bz2 from and save in the source folder.
cd /src
tar -xjf postgresql-8.2.5.tar.bz2
cd postgresql-8.2.5
In file src/include/port.h: Comment out or delete the line with the definition of the function gettimeofday().
In file src/include/port/win32.h: Comment out or delete the entire definition of struct timezone{}.
In file src/port/gettimeofday.c: Rename the function gettimeofday() to gettimeofday2().
Now continue:
./configure --prefix=/usr --with-libs=/usr/lib --with-includes=/usr/include --bindir=/usr/local/bin --with-openssl
make
make install
cp /usr/lib/*.dl* /usr/local/bin/
cp /usr/lib/postgresql/*.dll /usr/local/bin/ -R
**** SQLite 3.5.1 ****
SQLite is a drop-in replacement for DBF as a file-based attribute data storage that is more flexible and less limited (e.g. no 2GB maximum file size limit).
Download sqlite-3.5.1.tar.gz from and save it into the source directory.
cd /src
tar -xzvf sqlite-3.5.1.tar.gz
cd sqlite-3.5.1
./configure --bindir=/usr/local/bin --prefix=/usr --disable-static --enable-shared
make
We now need to create the DLL files for Win32 and install all neded binaries and header files manually, as the ``make install'' fails for various reasons with MinGW:
make sqlite3.dll
cp sqlite3.dll /usr/lib/libsqlite3.dll
cp sqlite3.h /usr/include
cp sqlite3.exe /usr/local/bin
**** MySQL 5.0.45 from Binaries ****
Download the file mysql-noinstall-5.0.45-win32.zip from and save it to any folder.
Uncompress the zip files contents, below the top level directory mysql-5.0.45-win32, to C:\msys\1.0\local\mysql, so that the subfolders bin, data, Docs, etc. go directly into C:\msys\1.0\local\mysql.
In order to get headers and DLLs to work with MinGW, a few adjustments are needed.
First, the libmysql.def file shipped with the MySQL binaries is missing mangled function names which the MinGW linker needs. Open the file C:\msys\1.0\local\mysql\include\libmysql.def in a text editor and make sure it has the following content:
LIBRARY LIBMYSQL
VERSION 6.0
EXPORTS
_dig_vec_lower
_dig_vec_upper
bmove_upp
delete_dynamic
free_defaults
getopt_compare_strings
getopt_ull_limit_value
handle_options
init_dynamic_array
insert_dynamic
int2str
is_prefix
list_add
list_delete
load_defaults
my_end
my_getopt_print_errors
my_init
my_malloc
my_memdup
my_no_flags_free
my_path
mysql_get_parameters
my_print_help
my_print_variables
my_realloc
my_strdup
mysql_thread_end
mysql_thread_init
myodbc_remove_escape
mysql_affected_rows
mysql_autocommit
mysql_stmt_bind_param
mysql_stmt_bind_result
mysql_change_user
mysql_character_set_name
mysql_close
mysql_commit
mysql_data_seek
mysql_debug
mysql_dump_debug_info
mysql_eof
mysql_errno
mysql_error
mysql_escape_string
mysql_hex_string
mysql_stmt_execute
mysql_stmt_fetch
mysql_stmt_fetch_column
mysql_fetch_field
mysql_fetch_field_direct
mysql_fetch_fields
mysql_fetch_lengths
mysql_fetch_row
mysql_field_count
mysql_field_seek
mysql_field_tell
mysql_free_result
mysql_get_client_info
mysql_get_host_info
mysql_get_proto_info
mysql_get_server_info
mysql_get_client_version
mysql_get_ssl_cipher
mysql_info
mysql_init
mysql_insert_id
mysql_kill
mysql_set_server_option
mysql_list_dbs
mysql_list_fields
mysql_list_processes
mysql_list_tables
mysql_more_results
mysql_next_result
mysql_num_fields
mysql_num_rows
mysql_odbc_escape_string
mysql_options
mysql_stmt_param_count
mysql_stmt_param_metadata
mysql_ping
mysql_stmt_result_metadata
mysql_query
mysql_read_query_result
mysql_real_connect
mysql_real_escape_string
mysql_real_query
mysql_refresh
mysql_rollback
mysql_row_seek
mysql_row_tell
mysql_select_db
mysql_stmt_send_long_data
mysql_send_query
mysql_shutdown
mysql_ssl_set
mysql_stat
mysql_stmt_affected_rows
mysql_stmt_close
mysql_stmt_reset
mysql_stmt_data_seek
mysql_stmt_errno
mysql_stmt_error
mysql_stmt_free_result
mysql_stmt_num_rows
mysql_stmt_row_seek
mysql_stmt_row_tell
mysql_stmt_store_result
mysql_store_result
mysql_thread_id
mysql_thread_safe
mysql_use_result
mysql_warning_count
mysql_stmt_sqlstate
mysql_sqlstate
mysql_get_server_version
set_dynamic
strcend
strcont
strdup_root
strfill
strinstr
strmake
strmov
strxmov
mysql_stmt_prepare
mysql_stmt_init
mysql_stmt_insert_id
mysql_stmt_attr_get
mysql_stmt_attr_set
mysql_stmt_field_count
client_errors
mysql_set_local_infile_default
mysql_set_local_infile_handler
mysql_disable_reads_from_master
mysql_disable_rpl_parse
mysql_enable_reads_from_master
mysql_enable_rpl_parse
mysql_master_query
mysql_rpl_parse_enabled
mysql_rpl_probe
mysql_rpl_query_type
mysql_slave_query
mysql_embedded
mysql_server_init
mysql_server_end
mysql_set_character_set
mysql_get_character_set_info
get_defaults_options
modify_defaults_file
mysql_affected_rows at 4
mysql_close at 4
mysql_error at 4
mysql_escape_string at 12
mysql_fetch_fields at 4
mysql_fetch_lengths at 4
mysql_fetch_row at 4
mysql_free_result at 4
mysql_init at 4
mysql_num_fields at 4
mysql_options at 12
mysql_query at 8
mysql_real_connect at 32
mysql_real_escape_string at 16
mysql_stmt_bind_param at 8
mysql_stmt_bind_result at 8
mysql_stmt_close at 4
mysql_stmt_error at 4
mysql_stmt_execute at 4
mysql_stmt_fetch at 4
mysql_stmt_free_result at 4
mysql_stmt_init at 4
mysql_stmt_param_count at 4
mysql_stmt_prepare at 12
mysql_stmt_result_metadata at 4
mysql_stmt_store_result at 4
mysql_store_result at 4
mysql_use_result at 4
myodbc_remove_escape at 8
mysql_autocommit at 8
mysql_change_user at 16
mysql_character_set_name at 4
mysql_commit at 4
mysql_connect
mysql_create_db
mysql_debug at 4
mysql_dump_debug_info at 4
mysql_eof at 4
mysql_fetch_field at 4
mysql_fetch_field_direct at 8
mysql_field_count at 4
mysql_field_seek at 8
mysql_field_tell at 4
mysql_get_client_info at 0
mysql_get_client_version at 0
mysql_get_host_info at 4
mysql_get_proto_info at 4
mysql_get_server_info at 4
mysql_get_server_version at 4
mysql_hex_string at 12
mysql_kill at 8
mysql_list_dbs at 8
mysql_list_fields at 12
mysql_list_processes at 4
mysql_list_tables at 8
mysql_more_results at 4
mysql_next_result at 4
mysql_num_rows at 4
mysql_ping at 4
mysql_real_query at 12
mysql_rollback at 4
mysql_row_tell at 4
mysql_select_db at 8
mysql_set_server_option at 8
mysql_shutdown at 8
mysql_sqlstate at 4
mysql_ssl_set at 24
mysql_stat at 4
mysql_stmt_affected_rows at 4
mysql_stmt_attr_get at 12
mysql_stmt_attr_set at 12
mysql_stmt_data_seek at 12
mysql_stmt_errno at 4
mysql_stmt_fetch_column at 16
mysql_stmt_field_count at 4
mysql_stmt_insert_id at 4
mysql_stmt_num_rows at 4
mysql_stmt_param_metadata at 4
mysql_stmt_reset at 4
mysql_stmt_row_seek at 8
mysql_stmt_row_tell at 4
mysql_stmt_send_long_data at 16
mysql_stmt_sqlstate at 4
mysql_thread_end at 0
mysql_thread_id at 4
mysql_thread_init at 0
mysql_thread_safe at 0
mysql_warning_count at 4
mysql_errno at 4
mysql_insert_id at 4
Now, re-generate the libraries:
cd /usr/local/mysql
dlltool --input-def include/libmySQL.def --dllname bin/libmysql.dll --output-lib bin/libmysqlclient.a -k
You need to adjust some lines in C:\msys\1.0\local\mysql\include\mysql.h. Locate the paragraph that reads:
#ifndef my_socket_defined
#ifdef __WIN__
#define my_socket SOCKET
#else
typedef int my_socket;
#endif /* __WIN__ */
#endif /* my_socket_defined */
#endif /* _global_h */
And change it to:
#ifndef my_socket_defined
#ifdef __WIN__
typedef int my_socket;
#endif /* __WIN__ */
#endif /* my_socket_defined */
#endif /* _global_h */
In C:\msys\1.0\etc\profile, extend the system path to include the MySQL programs:
export PATH="$PATH:/usr/local/mysql/bin:/usr/local/mysql/scripts"
Unfortunately, we need to do a little more clean-up work so that other software will be able to link to the MySQL libraries later.
Open the file C:\msys\local\mysql\include\config-win.h in a text editor.
Remove the entire code block that re-defines the function ``rint'' (ca. lines 227-232):
inline double rint(double nr)
{
double f = floor(nr);
double c = ceil(nr);
return (((c-nr) >= (nr-f)) ? f :c);
}
Remove the line (ca. 453) that re-defines the function ``popen'':
#define popen(A,B) _popen((A),(B))
Next, open the C:\msys\local\mysql\scripts\mysql_config in a text editor. This script tells other programs where to find MySQL libraries and include files. We need to fill in some information manually. Locate the lines that define the items ``pkglibdir'', ``pkgincludedir'', ``cflags'' and ``libs'' and change them to the following:
pkglibdir='/usr/local/mysql/bin'
pkgincludedir='/usr/local/mysql/include'
cflags="-I$pkgincludedir " #note: end space!
libs="-L$pkglibdir -lz -leay32 -lssleay32 -lmysql"
2. CONFIGURING GRASS
./configure --with-includes=/usr/include --with-libs=/usr/lib --enable-shared=yes --with-opengl=windows --with-curses --with-cxx --without-fftw --with-mysql --with-mysql-includes=/usr/local/mysql/include --with-mysql-libs=/usr/local/mysql/bin/ --with-odbc --with-postgres --with-sqlite --without-x11
More information about the Qgis-developer
mailing list