为iOS构建静态Graphviz库

8
我试图为Graphviz构建静态库,以便将它们包含在iOS应用程序中,但是我无法让它工作。到目前为止,我使用的是graphviz 2.28.0,Xcode 4.1和OSX 10.7,并且我正在针对iOS模拟器进行开发。我找到了Glen Low的配置说明,并进行了一些猜测,更新了这些说明。
./configure --build=i486-apple-darwin --host=arm-apple-darwin9 --disable-dependency-tracking --enable-shared=no --enable-static=yes --enable-ltdl-install=no --enable-ltdl=no --enable-swig=no --enable-tcl=no --with-codegens=no --with-fontconfig=no --with-freetype2=no --with-ipsepcola=yes --with-libgd=no --with-quartz=yes --with-visio=yes --with-x=no --with-cgraph=no CC="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2" CPP="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -E" CXX="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/g++-4.2" CXXCPP="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/g++-4.2 -E" OBJC="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2" LD="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ld" CPPFLAGS="-arch armv6 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk -miphoneos-version-min=4.0" CXXCPPFLAGS="-arch armv6 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk -miphoneos-version-min=4.0"

这个方法可以运行,但是"make"运行了一段时间后出现了错误:
Making all in gvpr
  CCLD   mkdefs
ld: warning: ignoring file mkdefs.o, file was built for armv6 which is not the architecture being linked (i386)
ld: warning: ignoring file /usr/local/lib/libSystem.dylib, missing required architecture i386 in file
ld: warning: symbol dyld_stub_binder not found, normally in libSystem.dylib
Undefined symbols for architecture i386:
  "_exit", referenced from:
      start in crt1.10.6.o
  "_main", referenced from:
      start in crt1.10.6.o
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status
make[3]: *** [mkdefs] Error 1
make[2]: *** [all-recursive] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

我不太理解所有的架构规范,所以任何帮助使其工作起来都是非常受欢迎的。

3个回答

2

我已经解决了这个问题。在构建脚本尝试生成可执行文件时,它失败了,因为它是针对i386编译而不是x86或x86_64,但所有的库都可以正常构建。

# For iPhoneOS
export DEV_iOS=/Developer/Platforms/iPhoneOS.platform/Developer
export SDK_iOS=${DEV_iOS}/SDKs/iPhoneOS5.0.sdk
export COMPILER_iOS=${DEV_iOS}/usr/bin
export CC=${COMPILER_iOS}/gcc
export CXX=${COMPILER_iOS}/g++
export LDFLAGS="-arch armv7 -pipe -Os -gdwarf-2 -no-cpp-precomp -mthumb -isysroot ${SDK_iOS}"
export CFLAGS=${LDFLAGS}
export CXXFLAGS=${LDFLAGS}
export LD=${COMPILER_iOS}/ld
export CPP=${COMPILER_iOS}/llvm-cpp-4.2
export AR=${COMPILER_iOS}/ar
export AS=${COMPILER_iOS}/as
export NM=${COMPILER_iOS}/nm
export CXXCPP=${COMPILER_iOS}/llvm-cpp-4.2
export RANLIB=${COMPILER_iOS}/ranlib

./configure --host=arm-apple-darwin11 --disable-dependency-tracking --enable-shared=no --enable-static=yes --enable-ltdl-install=no --enable-ltdl=no --enable-swig=no --enable-tcl=no --with-codegens=no --with-fontconfig=no --with-freetype2=no --with-ipsepcola=yes --with-libgd=no --with-quartz=yes --with-visio=yes --with-x=no --with-cgraph=no

请查看以下链接:https://dev59.com/K2TWa4cB1Zd3GeqPGLuH,根据您的回答。 - Andy Dent

2

问题在于mkdefs是在构建过程中创建后执行的。因此,如果您构建的是armv6或armv7,该文件无法在Mac OS X的命令行上执行。我的解决方法是为i386架构(也需要iPhone模拟器)构建一个mkdefs,并在出现此错误后将其复制到lib/gvpr目录中。确保文件无法被覆盖,并重新启动构建。


0

看起来链接器正在尝试链接到您的 Mac 上安装的系统库。这些库将全部编译为 i386 或 x86_64,当编译 iPhone 库时不会起作用。您需要重新配置链接器以链接到 iPhone SDK 中提供的库。

还应该注意,您可能需要将库编译两次——一次是 armv6,再一次是 armv7。iPhone 3G 和一些旧款 iPod Touch 使用 armv6 架构,而新款 iPhone 使用 armv7 架构。在两种架构下编译完库后,可以使用 lipo(在终端中键入“man lipo”获取更多信息)创建一个包含两种架构的单个静态库。如果您打算使用 iPhone/iPad 模拟器开发应用程序,则还建议编译一次 i386,以便您可以在模拟器中使用库。同样,lipo 可以创建一个包含所有 3 种架构的单个静态库。

目前GraphViz网站似乎无法访问,所以我无法像您一样下载库并运行配置脚本。但是我怀疑在运行“make”之前,您应该对由配置脚本生成的makefile进行以下更改。根据您针对的iOS SDK版本和计算机上安装的gcc版本,您可能需要调整以下某些更改,以使它们适用于您的环境。以下说明将构建armv6版本。一旦您准备好处理该架构,您将需要更改设置以构建armv7。

找到CC = cc并将其更改为: CC = /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2

在CFLAG中找到-arch i386并将其更改为: -arch armv6

在CFLAG中找到并添加到BEGINNING: -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.0.sdk

找到SHARED_LDFLAGS = -arch i386 -dynamiclib并将其更改为: SHARED_LDFLAGS = -arch armv6 -dynamiclib


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接