为 iOS 构建静态 Graphviz 库
我正在尝试为 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
我不太了解所有架构规范,因此非常欢迎任何帮助使其正常工作的帮助。
I am trying build the static libraries for Graphviz to include them in in an iOS app, but I can't get it to work. Here's what I have done so far, using graphviz 2.28.0], Xcode 4.1, OSX 10.7 and I am targeting the iOS simulator.
I found Glen Low's configure instructions, and with some informed guesswork updated these to:
./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"
This works, but then the "make" runs for a while and errors out with:
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
I don't quite understand all the architecture specifications, so any help to get this to work is most welcome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
问题是我认为 mkdefs 在创建后的构建过程中执行。因此,如果您为armv6或armv7构建,则该文件无法在Mac OS X的命令行上执行。我的解决方法是为架构i386构建一个mkdefs(iPhone模拟器也需要它)并将其复制到lib中出现此错误后的 /gvpr 目录。确保该文件无法被覆盖并重新启动构建。
Problem is imo that mkdefs is executed during the build process itself after it was created. So if you build for armv6 or armv7 the file can't be executed on the command line of Mac OS X. My workaround was to build a mkdefs for architecture i386 (which is needed for the iPhone simulator too) and copy it in the lib/gvpr directory after getting this error. Make sure that the file could not be overwritten and restart the build.
我得到了这个工作。当构建脚本尝试生成可执行文件时,它最终失败,因为它是为 i386 而不是 x86 或 x86_64 编译的,但所有库都构建得很好。
I got this working. The build script fails at the end when it tried to make an executable since it's compiled for i386 instead of x86 or x86_64 but all the libraries build just fine.
链接器似乎正在尝试链接到 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
It appears that the linker is trying to link to the system libraries installed on your Mac. Those libraries are all going to be compiled for i386 or x86_64 which isn't going to work when compiling libraries for iPhone. You'll need to reconfigure the linker to link against the libraries that come in the iPhone SDK.
It should also be noted that you will probably have to compile the library twice - once as armv6 and again as armv7. iPhone 3G and some of the older iPod Touches use the armv6 architecture, while newer iPhones use the armv7 architecture. After you've compiled the libraries under both architectures you can use lipo (type "man lipo" in your Terminal for more info) to create a single static library with both architectures in it. If you are going to develop your app using the iPhone/iPad simulator, then I also suggest compiling once as i386 so that you can use your library with the simulator. Again, lipo can create a single static library with all 3 architectures in it.
Now the GraphViz website appears to be unreachable at the moment, so I could not download the library and run the configure script like you did, but I suspect that before you run "make" you should make the following changes to the makefile that is produced by the configure script. Depending on which version of the iOS SDK you are targeting and what version of gcc you have on your machine you may have to tweak some of the changes below so they are appropriate for your environment. The instructions below will build for armv6. You'll need to change the settings to build for armv7 once you are ready to tackle that architecture.
Find CC= cc and change it to:
CC= /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2
Find -arch i386 in CFLAG and change it to:
-arch armv6
Find CFLAG and add to the BEGINNING!!:
-isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.0.sdk
Find SHARED_LDFLAGS=-arch i386 -dynamiclib and change it to:
SHARED_LDFLAGS=-arch armv6 -dynamiclib