繁体   English   中英

声明没有初始大小的数组

[英]Declaring arrays with no initial size

我正在尝试使用Visual Studio 2008在Windows Vista x64上编译OpenSSL(pyOpenSSL)的Python绑定。当我运行python setup.py build_ext -IC:\\OpenSSL\\include ,它会因以下错误而死机:

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

当我查看相关来源时,我在第16行看到以下内容:

static PyMethodDef crypto_X509Name_methods[];

我的C非常生疏,所以我不记得你是否可以这样做。 由于这是一个Python库,我猜这是用gcc编译的,但我没有在这台计算机上安装Cygwin环境。 是否有一些开关可用于使用VS2008编译此代码?

回答:

稍后在代码中,有这样的:

/*
 * 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

根据Neil Butterworth的建议,我改变了以下错误:

static PyMethodDef crypto_X509Name_methods[];

至:

static PyMethodDef crypto_X509Name_methods[4];

和编译的代码。

谢谢大家。

由于它是静态的,因此必须在某些编译单元(C源文件)中使用常量大小进行初始化。

你可能有这样的情况:

#include <stdio.h>

static int a[];     // declaration

// lots of code

int a[3];           // use

用gcc编译成C语言。 我不确定它应该是什么(它不是有效的C ++)但我不足以让C语言律师肯定地告诉你。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM