Problem building/using M2Crypto extension module

Ng Pheng Siong ngps at netmemetic.com
Thu Oct 2 22:43:22 EDT 2003


According to Carl Waldbieser <waldbie at attglobal.net>:
> If you get around to building it for Python2.3.x, I'd be glad to know how it
> went.  

Turns out I do have Python 2.3 installed on one of my
rarely-booted-into-Windows computer.

Here's what I get:

C:\ngps\prog\ngps\m2\SWIG>make -f Makefile.mw
c:/pkg/swig/swig.exe -shadow -python  _m2crypto.i
gcc -c -DTHREADING -g -Ic:/pkg/py23/include -Ic:/pkg/openssl/include -I. _m2cryp
to_wrap.c
[warnings deleted]
dllwrap --dllname __m2crypto.pyd --driver-name gcc \
            --def _m2crypto.def -o __m2crypto.pyd _m2crypto_wrap.o \
            -s --entry _DllMain at 12 --target=i386-mingw32 c:/pkg/py23/libs/libpyt
hon23.a c:/pkg/openssl/lib/libssl32.a c:/pkg/openssl/lib/libeay32.a
copy _m2crypto.py ..\M2Crypto
        1 file(s) copied.
copy __m2crypto.pyd ..\M2Crypto
        1 file(s) copied.

C:\ngps\prog\ngps\m2\SWIG>python
Python 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import __m2crypto
>>>


C:\ngps\prog\ngps\m2>python setup.py build -cmingw32
running build
running build_py
running build_ext
building '__m2crypto' extension
swigging SWIG/_m2crypto.i to SWIG/_m2crypto_wrap.c
c:\pkg\swig\swig.exe -python -ISWIG -o SWIG/_m2crypto_wrap.c SWIG/_m2crypto.i
g:\pkg\dev-c++\bin\gcc.exe -mno-cygwin -mdll -O -Wall -IC:\ngps\prog\ngps\m2\SWI
G -Ic:\pkg\openssl/include -Ic:\pkg\py23\include -Ic:\pkg\py23\PC -c SWIG/_m2cry
pto_wrap.c -o build\temp.win32-2.3\Release\swig\_m2crypto_wrap.o -DTHREADING
[warnings deleted]
writing build\temp.win32-2.3\Release\swig\__m2crypto.def
g:\pkg\dev-c++\bin\dllwrap.exe -mno-cygwin -mdll -static --output-lib build\temp
.win32-2.3\Release\swig\lib__m2crypto.a --def build\temp.win32-2.3\Release\swig\
__m2crypto.def -s build\temp.win32-2.3\Release\swig\_m2crypto_wrap.o -Lc:\pkg\op
enssl\lib -Lc:\pkg\py23\libs -Lc:\pkg\py23\PCBuild -lssleay32 -llibeay32 -lpytho
n23 -o build\lib.win32-2.3\M2Crypto\__m2crypto.pyd

C:\ngps\prog\ngps\m2>python setup.py install --skip-build
running install
running install_lib
creating c:\pkg\py23\Lib\site-packages\M2Crypto
copying build\lib.win32-2.3\M2Crypto\ASN1.py -> c:\pkg\py23\Lib\site-packages\M2
Crypto
[blah blah blah]
byte-compiling c:\pkg\py23\Lib\site-packages\M2Crypto\__init__.py to __init__.py
c

C:\>python
Python 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import M2Crypto
>>> dir(M2Crypto)
['ASN1', 'BIO', 'DH', 'DSA', 'EVP', 'Err', 'PGP', 'RC4', 'RCS_id', 'RSA', 'Rand'
, 'SSL', 'X509', '__builtins__', '__doc__', '__file__', '__m2crypto', '__name__'
, '__path__', 'decrypt', 'encrypt', 'httpslib', 'm2', 'm2urllib', 'urllib2', 'ut
il']
>>> from M2Crypto import RSA
>>> k = RSA.gen_key(512,65537)
............................++++++++++++
.............++++++++++++
>>>


You need mingw versions of libpython23.a, libssl32.a and libeay32.a. 

Makefile.mw says:

  SSLLIB=c:/pkg/openssl/lib/libssl32.a c:/pkg/openssl/lib/libeay32.a

Whereas, using setup.py, the command line constructed is "-lssleay32
-llibeay32", so you need libssleay32.a and liblibeay32.a. Somewhat
ridiculous looking, yes. ;-). This is because setup.py was written for
VC++; the relevant snippet looks like this:

  if os.name == 'nt':
      openssl_dir = 'c:\\pkg\\openssl'
      include_dirs = [my_inc, openssl_dir + '/include']
      library_dirs = [openssl_dir + '\\lib']
      libraries = ['ssleay32', 'libeay32']
      #libraries = ['ssleay32_bc', 'libeay32_bc']
      extra_compile_args = [ "-DTHREADING" ]

So, alternatively, you can modify the "libraries" line to say "['ssl32',
'eay32']" (I think) to use the default library names assigned to OpenSSL
libraries by mingw. (On Unix they're called libssl.so and libcrypto.so.
Duh!)

Notice "['ssleay_bc', 'libeay_bc']". That's for Borland's free compiler
suite. I haven't tested this in a long while. Going forward, it will be
mingw only.

HTH. 


-- 
Ng Pheng Siong <ngps at netmemetic.com> 

http://firewall.rulemaker.net  -+- Manage Your Firewall Rulebase Changes
http://sandbox.rulemaker.net/ngps -+- Open Source Python Crypto & SSL




More information about the Python-list mailing list