tags:

views:

248

answers:

2

I am trying to compile the Python bindings for OpenSSL (pyOpenSSL) on Windows Vista x64 using Visual Studio 2008. When I run python setup.py build_ext -I C:\OpenSSL\include, it dies with the following error:

building 'OpenSSL.crypto' extension
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -I\OpenSSL\include -IC:\Python26\include -IC:\Python26\PC /Tcsrc/crypto/x509name.c /Fobuild\temp.win-amd64-2.6\Release\src/crypto/x509name.obj
x509name.c
src/crypto/x509name.c(16) : error C2133: 'crypto_X509Name_methods' : unknown size
error: command '"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\amd64\cl.exe"' failed with exit status 2

When I look at the source in question, I see the following at line 16:

static PyMethodDef crypto_X509Name_methods[];

My C is very rusty, so I don't remember if you can do this or not. Since this is a Python library, I would guess that is is written to compile in gcc, but I don't have a Cygwin environment installed on this computer. Is there some switch that I can use to get this code to compile with VS2008?

Answer:

Later on in the code, there is this:

/*
 * ADD_METHOD(name) expands to a correct PyMethodDef declaration
 *   {  'name', (PyCFunction)crypto_X509_name, METH_VARARGS }
 * for convenience
 */
#define ADD_METHOD(name)        \
    { #name, (PyCFunction)crypto_X509Name_##name, METH_VARARGS,  crypto_X509Name_##name##_doc }
static PyMethodDef crypto_X509Name_methods[] =
{
    ADD_METHOD(hash),
    ADD_METHOD(der),
    ADD_METHOD(get_components),
    { NULL, NULL }
};
#undef ADD_METHOD

Going off of the suggestion of Neil Butterworth, I changed the line in error from:

static PyMethodDef crypto_X509Name_methods[];

to:

static PyMethodDef crypto_X509Name_methods[4];

and the code compiled.

Thanks to everyone.

+5  A: 

Since it's static it must be initialized with a constant size in some compilation unit (C source file).

Hernán
it must be initialized in **the same** compilation unit, you mean, right?
Juliano
Yes of course (but warn, it's not the same *file* [in general]).
Hernán
+5  A: 

You probably have a situation like this:

#include <stdio.h>

static int a[];     // declaration

// lots of code

int a[3];           // use

which compiles as C with gcc. I'm not sure it should (it is not valid C++) but I'm not enough of a C language lawyer to tell you for sure.

anon