我正在尝试在运行Mac OS 10.6.5的64位Mac上构建python-nss的Python接口,用于在Mac OS X 10.6或更高版本上运行的python软件中使用。我可以使用某些选项让NSS本身成功构建,但是python-nss构建会给出一些警告,并且生成的Python模块不可用。
为了构建NSS,我遵循Mozilla NSS library,但是使用此these instructions,而不是从cvs进行检出。如果我只运行make nss_build_all
,则会遇到错误:
ncraike@ncraikework ~/Installs/nss-3.12.9/mozilla/security/nss
$ make nss_build_all
...
drbg.c: In function ‘RNG_RandomUpdate’:
drbg.c:516: error: size of array ‘arg’ is negative
make[3]: *** [Darwin10.5.0_DBG.OBJ/Darwin_SINGLE_SHLIB/drbg.o] Error 1
make[2]: *** [libs] Error 2
make[1]: *** [libs] Error 2
make: *** [libs] Error 2
有问题的行(
mozilla/security/nss/lib/freebl/drbg.c
的第516行)断言特定类型具有预期的大小: PR_STATIC_ASSERT(sizeof(size_t) <= 4);
如果我编写一个快速测试程序,sizeof(size_t)似乎是8,那么尽管在上面的说明页面上有此说明,但也许正在构建64位版本:
在Alpha / OSF1以外的Unix平台上,如果要构建系统的64位ABI,请在您的环境中设置USE_64 = 1。默认情况下,NSS在除Alpha / OSF1之外的所有平台上为32位环境构建。
添加gcc选项
-arch i386
(为NSS source code推荐)无济于事,但是使用USE_64环境变量构建成功(尽管我可能不需要64位构建):ncraike@ncraikework ~/Installs/nss-3.12.9/mozilla/security/nss
$ USE_64=1 make nss_build_all
这可能很好,但是当我尝试构建python-nss(使用similar issue)时会出现问题。
需要对python-nss的
setup.py
进行一些修改,以包括刚刚构建的NSS库。原始的setup.py
硬编码每个扩展名的包含目录,例如:nss_nss_extension = \
Extension('nss.nss',
sources = ['src/py_nss.c'],
include_dirs = ['src', '/usr/include/nss3', '/usr/include/nspr4'],
libraries = ['nspr4', 'ssl3', 'nss3'],
extra_compile_args = extra_compile_args,
)
因此,我通过添加以下几行来修改扩展声明:
DIST_ROOT = '/Users/ncraike/Installs/nss-3.12.9/mozilla/dist/'
INCLUDE_DIRS = [DIST_ROOT+'Darwin10.5.0_64_DBG.OBJ/include', DIST_ROOT+'public/nss/', DIST_ROOT+'private/nss/']
LIB_DIRS = [DIST_ROOT+'Darwin10.5.0_64_DBG.OBJ/lib/']
...并更改每个扩展名以添加INCLUDE_DIRS列表并包括
library_dirs
参数(如中所述)。例如:nss_nss_extension = \
Extension('nss.nss',
sources = ['src/py_nss.c'],
include_dirs = ['src'] + INCLUDE_DIRS,
libraries = ['nspr4', 'ssl3', 'nss3'],
library_dirs = LIB_DIRS,
extra_compile_args = extra_compile_args,
)
完成这些更改后,
python setup.py build
运行并且似乎知道NSS库,但是会产生一些警告,包括:src/py_nss.c:12640: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘Py_ssize_t’
gcc-4.2 -Wl,-F. -bundle -undefined dynamic_lookup -arch i386 -arch ppc -arch x86_64 build/temp.macosx-10.6-universal-2.6/src/py_nss.o -L/Users/ncraike/Installs/nss-3.12.9/mozilla/dist/Darwin10.5.0_64_DBG.OBJ/lib/ -lnspr4 -lssl3 -lnss3 -o build/lib.macosx-10.6-universal-2.6/nss/nss.so
ld: warning: in build/temp.macosx-10.6-universal-2.6/src/py_nss.o, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in /Users/ncraike/Installs/nss-3.12.9/mozilla/dist/Darwin10.5.0_64_DBG.OBJ/lib//libnspr4.dylib, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in /Users/ncraike/Installs/nss-3.12.9/mozilla/dist/Darwin10.5.0_64_DBG.OBJ/lib//libssl3.dylib, file was built for unsupported file format which is not the architecture being linked (i386)
“最常见的警告是:“文件是为不受支持的文件格式构建的,不是链接的体系结构”。 this source中提到了此错误,并提供了将
-arch i386
选项与gcc一起使用的可能解决方案。我不确定在构建过程中的哪个步骤添加此选项(NSS或python-nss?),以及如何将其添加到python distutils构建脚本中。构建确实完成,但是生成的python模块似乎不可用:
ncraike@ncraikework ~/Installs/python-nss-0.10/build/lib.macosx-10.6-universal-2.6
$ ls
nss
ncraike@ncraikework ~/Installs/python-nss-0.10/build/lib.macosx-10.6-universal-2.6
$ python
Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import nss.nss
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dlopen(nss/nss.so, 2): Library not loaded: @executable_path/libssl3.dylib
Referenced from: /Users/ncraike/Installs/python-nss-0.10/build/lib.macosx-10.6-universal-2.6/nss/nss.so
Reason: image not found
我在构建NSS或构建python-nss时是否出错?我应该如何告诉python-nss构建脚本正确地与Mac OS X NSS库链接?我拥有比C经验更多的python经验,因此,如果我犯了一些简单的构建错误,我不会感到惊讶。
我正在运行Mac OS 10.6.5,安装了Xcode 3.2.4(64位)。
gcc -v
给出gcc version 4.2.1 (Apple Inc. build 5664)
和Target: i686-apple-darwin10
。谢谢。
最佳答案
在OSX 10.7中,默认情况下具有llvm-gcc和llvm-g ++。他们通常会打印出更多口头错误消息。
cc -o Darwin11.3.0_DBG.OBJ/Darwin_SINGLE_SHLIB/drbg.o -c -g -fPIC -Di386 -Wmost -fpascal-strings -fno-common -pipe -DDARWIN -DHAVE_STRERROR -DHAVE_BSD_FLOCK -DXP_UNIX -DSHLIB_SUFFIX=\"dylib\" -DSHLIB_PREFIX=\"lib\" -DSHLIB_VERSION=\"3\" -DSOFTOKEN_SHLIB_VERSION=\"3\" -DRIJNDAEL_INCLUDE_TABLES -DDEBUG -UNDEBUG -DDEBUG_antkong -DUSE_UTIL_DIRECTLY -DMP_API_COMPATIBLE -I../../../../dist/Darwin11.3.0_DBG.OBJ/include -I../../../../dist/public/nss -I../../../../dist/private/nss -Impi -Iecl drbg.c
drbg.c:471:34: warning: implicit conversion from enumeration type 'PRStatus' to different enumeration type 'SECStatus' (aka 'enum _SECStatus') [-Wconversion]
return (globalrng != NULL) ? PR_SUCCESS : PR_FAILURE;
~ ^~~~~~~~~~
drbg.c:471:47: warning: implicit conversion from enumeration type 'PRStatus' to different enumeration type 'SECStatus' (aka 'enum _SECStatus') [-Wconversion]
return (globalrng != NULL) ? PR_SUCCESS : PR_FAILURE;
~ ^~~~~~~~~~
drbg.c:516:5: error: 'arg' declared as an array with a negative size
PR_STATIC_ASSERT(sizeof(size_t) <= 4);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../../../dist/Darwin11.3.0_DBG.OBJ/include/prtypes.h:528:42: note: expanded from macro 'PR_STATIC_ASSERT'
extern void pr_static_assert(int arg[(condition) ? 1 : -1])
^~~~~~~~~~~~~~~~~~~~
2 warnings and 1 error generated.
希望他们可以帮助您找到解决方案或向Mozilla NSS项目提交错误报告