如何为 Mac OS X 构建 python-nss 和 NSS?

发布于 2024-10-12 10:33:07 字数 5721 浏览 3 评论 0 原文

我正在尝试构建 python-nss ,64 位 Mac 上 Mozilla NSS 库 的 Python 接口运行 Mac OS 10.6.5,用于在 Mac OS X 10.6 或更高版本上运行的 python 软件。我可以使用某些选项成功构建 NSS 本身,但 python-nss 构建会给出几个警告,并且生成的 Python 模块不可用。

要构建 NSS,我遵循这些说明,但使用此NSS 源代码,而不是从 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 (建议用于 类似问题)没有帮助,但是使用 USE_64 环境变量构建是成功的(尽管 64 位构建可能不是我需要的):

ncraike@ncraikework ~/Installs/nss-3.12.9/mozilla/security/nss
$ USE_64=1 make nss_build_all

这可能没问题,但是当我尝试构建 python-nss 时会出现问题(使用 此源)。

需要对 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 文档)。例如:

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)

“文件是为不支持的文件格式构建的,该文件格式不是架构被链接”是最常见的警告。 另一个网站上的帖子,其中包含使用 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 库?我的 python 经验比 C 经验多得多,所以如果我犯了一些简单的构建错误,我不会感到惊讶。

我运行的是 Mac OS 10.6.5,安装了 Xcode 3.2.4(64 位)。 gcc -v 给出 gcc 版本 4.2.1(Apple Inc. build 5664)目标:i686-apple-darwin10

谢谢。

I'm trying to build python-nss, a python interface for the Mozilla NSS library, on a 64-bit Mac running Mac OS 10.6.5, for use in python software running on Mac OS X 10.6 or later. I can get NSS itself to build successfully, using certain options, but the python-nss build gives several warnings, and the resulting Python module isn't usable.

To build NSS, I'm following these instructions, but using this NSS source code, rather than a checkout from cvs. If I just run make nss_build_all, I encounter an error:

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

The line in question (line 516 of mozilla/security/nss/lib/freebl/drbg.c) is an assertion that a particular type is of an expected size:

    PR_STATIC_ASSERT(sizeof(size_t) <= 4);

If I write a quick test program, sizeof(size_t) seems to be 8, so perhaps the 64-bit version is being built, despite this on the above instructions page:

On Unix platforms, except Alpha/OSF1, if you want a build for the system's 64-bit ABI, set USE_64=1 in your environment. By default, NSS builds for the 32-bit environment on all platforms except Alpha/OSF1.

Adding the gcc option -arch i386 (suggested for a similar issue) doesn't help, but building with the USE_64 environment variable is successful (although a 64-bit build may not be what I need):

ncraike@ncraikework ~/Installs/nss-3.12.9/mozilla/security/nss
$ USE_64=1 make nss_build_all

This may be fine, but problems occur when I try to build python-nss (using this source).

Some modifications to python-nss's setup.py are needed to include the NSS libraries just built. The original setup.py hard-codes the include directories for each extension, for example:

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,
              )

So I've modified the extension declarations by adding these lines:

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/']

...and changing each extension to add an INCLUDE_DIRS list and include a library_dirs argument (as described in the distutils documentation). For example:

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,
              )

After these changes, python setup.py build runs and seems to be aware of the NSS libraries, but produces several warnings, including:

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)

"file was built for unsupported file format which is not the architecture being linked" is the most common warning. This error is mentioned in a post on another site, with a possible solution of using the -arch i386 option with gcc. I'm not sure at what step in the build process to add this option (NSS or python-nss?), and how I might add it to the python distutils build script.

The build does complete, but the resulting python module doesn't seem usable:

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

Is my error in how I'm building NSS or how I'm building python-nss? How should I be telling the python-nss build script to link with the Mac OS X NSS libraries correctly? I have much more python experience than C experience, so if I've made some simple building error I won't be surprised.

I'm running Mac OS 10.6.5, with Xcode 3.2.4 (64-bit) installed. gcc -v gives gcc version 4.2.1 (Apple Inc. build 5664) and Target: i686-apple-darwin10.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅语花开 2024-10-19 10:33:07

在 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 项目提交错误报告

In OSX 10.7 we have llvm-gcc and llvm-g++ by default. They usually print out more verbal error messages.

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.

Hopefully they may help you to find a solution or file a bug report with Mozilla NSS project

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文