我正在尝试在运行Mac OS 10.6.5的64位Mac上构建python-nss,Mozilla NSS library的python接口,用于在Mac OS X 10.6上运行的python软件或以后。我可以使用某些选项让NSS本身成功构建,但是python-nss构建会产生一些警告,并且生成的Python模块不可用。
要构建NSS,我正在关注these instructions,但使用此NSS source code,而不是从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位版本,尽管如上所述:
在Unix平台上,除Alpha / OSF1外,如果要为系统的64位ABI构建,请在您的环境中设置USE_64 = 1。默认情况下,NSS在除Alpha / OSF1之外的所有平台上为32位环境构建。
添加gcc选项-arch i386
(建议用于similar issue)没有帮助,但使用USE_64环境变量构建是成功的(尽管64位构建可能不是我需要的) :
ncraike@ncraikework ~/Installs/nss-3.12.9/mozilla/security/nss
$ USE_64=1 make nss_build_all
这可能没问题,但是当我尝试构建python-nss(使用this source)时会出现问题。
需要对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
参数(如distutils documentation中所述)。例如:
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)
“文件是为不受支持的文件格式构建的,而不是被链接的体系结构”是最常见的警告。 a post on another site中提到了此错误,并提供了使用gcc的-arch i386
选项的可能解决方案。我不确定构建过程中的哪一步添加此选项(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
。
感谢。
答案 0 :(得分:0)
在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项目提交错误报告