Commit 68c0a85e authored by gabrieldemarmiesse's avatar gabrieldemarmiesse

Moved the building and installation into the dynamic linking. Changed some phrasing too.

parent 066118b1
...@@ -24,28 +24,11 @@ type that can encapsulate all memory management. ...@@ -24,28 +24,11 @@ type that can encapsulate all memory management.
.. [CAlg] Simon Howard, C Algorithms library, http://c-algorithms.sourceforge.net/ .. [CAlg] Simon Howard, C Algorithms library, http://c-algorithms.sourceforge.net/
.. _download_and_install_calg: Defining external declarations
==============================
Download & Install [CAlg]
==========================
You can download CAlg `here <https://github.com/fragglet/c-algorithms/archive/master.zip>`_. You can download CAlg `here <https://github.com/fragglet/c-algorithms/archive/master.zip>`_.
You may want to test whether you can build c-algorithms on your system using (not necessary)::
$ cd c-algorithms
$ sh autogen.sh
$ ./configure
$ make
to install CAlg run::
$ make install
Defining external declarations
===============================
The C API of the queue implementation, which is defined in the header The C API of the queue implementation, which is defined in the header
file ``c-algorithms/src/queue.h``, essentially looks like this:: file ``c-algorithms/src/queue.h``, essentially looks like this::
...@@ -192,7 +175,7 @@ the type. ...@@ -192,7 +175,7 @@ the type.
Memory management Memory management
==================== =================
Before we continue implementing the other methods, it is important to Before we continue implementing the other methods, it is important to
understand that the above implementation is not safe. In case understand that the above implementation is not safe. In case
...@@ -266,7 +249,7 @@ Static Linking ...@@ -266,7 +249,7 @@ Static Linking
To build the c-code automatically we need to include compiler directives in `queue.pyx`:: To build the c-code automatically we need to include compiler directives in `queue.pyx`::
# distutils: sources = c-algorithms/src/queue.c # distutils: sources = c-algorithms/src/queue.c
# distutils: include_dirs = c-algorithms/src/ # distutils: include_dirs = c-algorithms/src/
cimport cqueue cimport cqueue
...@@ -282,15 +265,16 @@ To build the c-code automatically we need to include compiler directives in `que ...@@ -282,15 +265,16 @@ To build the c-code automatically we need to include compiler directives in `que
cqueue.queue_free(self._c_queue) cqueue.queue_free(self._c_queue)
The ``sources`` compiler directive gives the path of the C The ``sources`` compiler directive gives the path of the C
files that distutils is going to compile. files that distutils is going to compile and
link (statically) into the resulting extension module.
In general all relevant header files should be found in ``include_dirs``. In general all relevant header files should be found in ``include_dirs``.
Now we can build the project using:: Now we can build the project using::
$ python setup.py build_ext -i $ python setup.py build_ext -i
And test whether our build was successful:: And test whether our build was successful::
$ python -c 'import queue; Q = queue.Queue()' $ python -c 'import queue; Q = queue.Queue()'
Dynamic Linking Dynamic Linking
...@@ -298,15 +282,26 @@ Dynamic Linking ...@@ -298,15 +282,26 @@ Dynamic Linking
Dynamic linking is useful, if the library we are going to wrap is already Dynamic linking is useful, if the library we are going to wrap is already
installed on the system. To perform dynamic linking we first need to installed on the system. To perform dynamic linking we first need to
build and install c-alg. Follow the instruction in build and install c-alg.
paragraph :ref:`download_and_install_calg` to install the library. Afterwards the
file :file:`/usr/local/lib/libcalg.so` should exist. To build c-algorithms on your system::
$ cd c-algorithms
$ sh autogen.sh
$ ./configure
$ make
to install CAlg run::
$ make install
Afterwards the file :file:`/usr/local/lib/libcalg.so` should exist.
.. note:: .. note::
This path may be different on different platforms, This path applies to Linux systems and may be different,
so you will need to adapt the rest of the tutorial depending on the so you will need to adapt the rest of the tutorial depending on the
where `libcalg.so` is on your system. where ``libcalg.so`` or ``libcalg.dll`` is on your system.
In this approach we need to tell the setup script to link with an external library. In this approach we need to tell the setup script to link with an external library.
To do so we need to extend the setup script to install change the extension setup from To do so we need to extend the setup script to install change the extension setup from
...@@ -326,7 +321,7 @@ to ...@@ -326,7 +321,7 @@ to
Now we should be able to build the project using:: Now we should be able to build the project using::
$ python setup.py build_ext -i $ python setup.py build_ext -i
If the `libcalg` is not installed in a 'normal' location, users can provide the If the `libcalg` is not installed in a 'normal' location, users can provide the
required parameters externally by passing appropriate C compiler required parameters externally by passing appropriate C compiler
...@@ -346,6 +341,7 @@ the `LD_LIBRARY_PATH` environment variable, e.g. by setting:: ...@@ -346,6 +341,7 @@ the `LD_LIBRARY_PATH` environment variable, e.g. by setting::
Once we have compiled the module for the first time, we can now import Once we have compiled the module for the first time, we can now import
it and instantiate a new Queue:: it and instantiate a new Queue::
$ export PYTHONPATH=.
$ python -c 'import queue; Q = queue.Queue()' $ python -c 'import queue; Q = queue.Queue()'
However, this is all our Queue class can do so far, so let's make it However, this is all our Queue class can do so far, so let's make it
...@@ -590,8 +586,6 @@ instead that accepts an arbitrary Python iterable:: ...@@ -590,8 +586,6 @@ instead that accepts an arbitrary Python iterable::
Now we can test our Queue implementation using a python script, Now we can test our Queue implementation using a python script,
for example here :file:`test_queue.py`.:: for example here :file:`test_queue.py`.::
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function from __future__ import print_function
import queue import queue
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment