在mac os x上安装python包autopy时遇到libpng和png.h问题
我在想有没有人能帮我解决这个问题。当我尝试运行 python setup.py build(或者 pip install,或者 easy_install)时,就出现了这样的情况:
大致内容是:
src/png_io.c:3:17: error: png.h: No such file or directory
src/png_io.c: In function ‘newMMBitmapFromPNG’:
src/png_io.c:34: error: ‘png_struct’ undeclared (first use in this function)
src/png_io.c:34: error: (Each undeclared identifier is reported only once
... 一堆错误 ...
src/png_io.c:332: error: ‘PNG_TRANSFORM_IDENTITY’ undeclared (first use in this function)
lipo: can't figure out the architecture type of: /var/folders/kt/d8t29zkx7kd_7c_mr17ntv6m0000gn/T//ccubs4CM.out
error: command 'gcc-4.2' failed with exit status 1
libpng 在 Library/Frameworks 目录下,而这个目录在搜索路径中(我用 cpp -v 检查过),但是它的形式是 libpng.framework,头文件则在一个叫做 headers 的子目录里。libpng.framework 文件中还有多个版本的 libpng。我现在使用的是 64 位的 Python。有没有什么建议我该怎么做?
谢谢,
Pat
2 个回答
0
在这个特定的情况下,是因为你缺少了libpng这个东西。(就是那个包含png.h的框架)
你可以从 http://ethan.tira-thompson.com/Mac_OS_X_Ports.html 下载它,然后重新运行autopy的安装,这样就可以正常使用了!
2
这个错误,正如你猜的那样,是因为编译器找不到头文件 png.h。
你能告诉我你是怎么包含这个框架的吗?你有使用 -I 和 -L 吗?
用 GCC 包含框架的正确写法是:
gcc -F*dir*
或者
gcc -iframework*dir*
希望这对你有帮助。
来自 http://gcc.gnu.org/onlinedocs/gcc/Darwin-Options.html
-Fdir
将框架目录 dir 添加到搜索头文件的目录列表的最前面。这些目录会和通过 -I 选项指定的目录交替排列,并从左到右进行扫描。
A framework directory is a directory with frameworks in it. A framework is a directory with a Headers and/or PrivateHeaders directory contained directly in it that ends in .framework. The name of a framework is the name of this directory excluding the .framework. Headers associated with the framework are found in one of those two directories, with Headers being searched first. A subframework is a framework directory that is in a framework's Frameworks directory. Includes of subframework headers can only appear in a header of a framework that contains the subframework, or in a sibling subframework header. Two subframeworks are siblings if they occur in the same framework. A subframework should not have the same name as a framework, a warning will be issued if this is violated. Currently a subframework cannot have subframeworks, in the future, the mechanism may be extended to support this. The standard frameworks can be found in /System/Library/Frameworks and /Library/Frameworks. An example include looks like #include <Framework/header.h>, where Framework denotes the name of the framework and header.h is found in the PrivateHeaders or Headers directory.