Skip to content

Commit 568cf52

Browse files
committed
Merge pull request PyMySQL#32 from PyMySQL/library-args
Pass options in `mysql_config --libs` to `extra_linker_args`
2 parents 61c6b56 + 009f157 commit 568cf52

File tree

2 files changed

+22
-89
lines changed

2 files changed

+22
-89
lines changed

INSTALL

+13-71
Original file line numberDiff line numberDiff line change
@@ -8,57 +8,25 @@ MySQLdb Installation
88
Prerequisites
99
-------------
1010

11-
+ Python 2.3.4 or higher
11+
+ Python 2.6, 2.7, 3.3 or higher
1212

1313
* http://www.python.org/
1414

15-
* Versions lower than 2.3 WON'T WORK.
16-
17-
* 2.4 is the primary test environment.
18-
19-
* Red Hat Linux:
20-
21-
- Make sure you have the Python development headers and libraries
22-
(python-devel).
23-
2415
+ setuptools
2516

2617
* http://pypi.python.org/pypi/setuptools
2718

28-
+ MySQL 3.23.32 or higher
19+
+ MySQL 5.0 or higher
2920

3021
* http://www.mysql.com/downloads/
3122

32-
* Versions lower than 3.22 definitely WON'T WORK.
33-
34-
* Versions lower than 3.22.19 might not work.
35-
36-
* MySQL-3.22 might work but isn't supported anymore. It's very old.
37-
38-
* MySQL-3.23 ought to work, but it's pretty elderly.
39-
40-
* MySQL-4.0 is supported, but not tested and slightly discouraged.
41-
42-
* MySQL-4.1 is supported. The prepared statements API is not
43-
supported, and won't be until MySQLdb-1.3 or 2.0, if ever.
23+
* MySQL-4.0 and MySQL-4.1 may work, but not supported.
4424

4525
* MySQL-5.0 is supported and tested, including stored procedures.
4626

4727
* MySQL-5.1 is supported (currently a release candidate) but untested.
4828
It should work.
4929

50-
* MySQL-6.0 is sorta-kinda-supported (currently alpha) but untested.
51-
It should work.
52-
53-
* Drizzle <https://launchpad.net/drizzle> is a fork of MySQL. So far
54-
the C API looks really similar except everything is renamed.
55-
Drizzle support probably won't happen in 1.2. There may be have to
56-
be an entirely different module, but still using DB-API.
57-
58-
* MaxDB, formerly known as SAP DB (and maybe Adabas D?), is a
59-
completely different animal. Use the sapdb.sql module that comes
60-
with MaxDB.
61-
6230
* Red Hat Linux packages:
6331

6432
- mysql-devel to compile
@@ -75,38 +43,15 @@ Prerequisites
7543

7644
- MySQL-shared to run if you compiled with MySQL-shared installed
7745

78-
* Transactions (particularly InnoDB tables) are supported for
79-
MySQL-3.23 and up. You may need a special package from your vendor
80-
with this support turned on.
81-
82-
+ zlib
83-
84-
* Required for MySQL-3.23 and newer.
85-
86-
* Red Hat Linux
87-
88-
- zlib-devel to compile
89-
90-
- zlib to run
91-
92-
+ openssl
93-
94-
* May be needed for MySQL-4.0 or newer, depending on compilation
95-
options. If you need it, you probably already have it.
96-
97-
- you may need openssl-devel on some platforms
98-
9946
+ C compiler
10047

10148
* Most free software-based systems already have this, usually gcc.
10249

10350
* Most commercial UNIX platforms also come with a C compiler, or
10451
you can also use gcc.
10552

106-
* If you have some Windows flavor, you usually have to pay extra
107-
for this, or you can use Cygwin_.
108-
109-
.. _Cygwin: http://www.cygwin.com/
53+
* If you have some Windows flavor, you should use Windows SDK or
54+
Visual C++.
11055

11156

11257
Building and installing
@@ -134,12 +79,18 @@ edit the [options] section of site.cfg:
13479
if True, try to link against a static library; otherwise link
13580
against dynamic libraries (default). You may need static linking
13681
to use the embedded server.
82+
This option doesn't work for MySQL>5.6 since libmysqlclient
83+
requires libstdc++. If you want to use, add `-lstdc++` to
84+
mysql_config manually.
13785

86+
If `<mysql prefix>/lib` is not added to `/etc/ld.so.conf`, `import _mysql`
87+
doesn't work. To fix this, (1) set `LD_LIBRARY_PATH`, or (2) add
88+
`-Wl,-rpath,<mysql prefix>/lib` to ldflags in your mysql_config.
13889

13990
Finally, putting it together::
14091

141-
$ tar xfz MySQL-python-1.2.1.tar.gz
142-
$ cd MySQL-python-1.2.1
92+
$ tar xz mysqlclient-1.3.6.tar.gz
93+
$ cd mysqlclient-1.3.6
14394
$ # edit site.cfg if necessary
14495
$ python setup.py build
14596
$ sudo python setup.py install # or su first
@@ -168,15 +119,6 @@ On Windows, you will definitely have to edit site.cfg since there is
168119
no mysql_config in the MySQL package.
169120

170121

171-
Zope
172-
....
173-
174-
If you are using a binary package of Zope, you need run setup.py with
175-
the python executable that came with Zope. Otherwise, you'll install
176-
into the wrong Python tree and Zope (ZMySQLDA) will not be able to
177-
find _mysql.
178-
179-
180122
Binary Packages
181123
---------------
182124

setup_posix.py

+9-18
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ def dequote(s):
1313
s = s[1:-1]
1414
return s
1515

16-
def compiler_flag(f):
17-
return "-%s" % f
18-
1916
def mysql_config(what):
2017
from os import popen
2118

@@ -53,29 +50,24 @@ def get_config():
5350
libs = mysql_config("libs")
5451
client = "mysqlclient"
5552

56-
library_dirs = [ dequote(i[2:]) for i in libs if i.startswith(compiler_flag("L")) ]
57-
libraries = [ dequote(i[2:]) for i in libs if i.startswith(compiler_flag("l")) ]
53+
library_dirs = [dequote(i[2:]) for i in libs if i.startswith('-L')]
54+
libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')]
55+
extra_link_args = [x for x in libs if not x.startswith(('-l', '-L'))]
5856

59-
removable_compile_args = [ compiler_flag(f) for f in "ILl" ]
60-
extra_compile_args = [ i.replace("%", "%%") for i in mysql_config("cflags")
61-
if i[:2] not in removable_compile_args ]
57+
removable_compile_args = ('-I', '-L', '-l')
58+
extra_compile_args = [i.replace("%", "%%") for i in mysql_config("cflags")
59+
if i[:2] not in removable_compile_args]
6260

6361
# Copy the arch flags for linking as well
64-
extra_link_args = list()
6562
for i in range(len(extra_compile_args)):
6663
if extra_compile_args[i] == '-arch':
6764
extra_link_args += ['-arch', extra_compile_args[i + 1]]
6865

69-
include_dirs = [ dequote(i[2:])
70-
for i in mysql_config('include')
71-
if i.startswith(compiler_flag('I')) ]
72-
if not include_dirs: # fix for MySQL-3.23
73-
include_dirs = [ dequote(i[2:])
74-
for i in mysql_config('cflags')
75-
if i.startswith(compiler_flag('I')) ]
66+
include_dirs = [dequote(i[2:])
67+
for i in mysql_config('include') if i.startswith('-I')]
7668

7769
if static:
78-
extra_objects.append(os.path.join(library_dirs[0],'lib%s.a' % client))
70+
extra_objects.append(os.path.join(library_dirs[0], 'lib%s.a' % client))
7971
if client in libraries:
8072
libraries.remove(client)
8173

@@ -104,4 +96,3 @@ def get_config():
10496

10597
if __name__ == "__main__":
10698
sys.stderr.write("""You shouldn't be running this directly; it is used by setup.py.""")
107-

0 commit comments

Comments
 (0)