交叉编译Makefile:处理测试程序
我正在尝试将几个库从 OSX 交叉编译到 iOS。我已经成功交叉编译了 libjpeg 和 libogg。
但我无法编译 libvorbis,因为 configure
坚持创建并运行一个小型测试程序。这显然失败了,因为它创建了一个armv7二进制文件,无法运行它,然后将其解释为缺少ogg库。
您通常如何处理此类问题?我很想破解配置脚本来解决这些问题,但由于这种故障,某些功能可能会被禁用。我也在考虑让 configure
生成一个本机 Makefile,然后将其转换为使用 iOS 工具链,但这似乎太容易出错。
有什么建议吗?
I'm trying to cross-compile several libraries from OSX to iOS. I've successfully cross-compiled libjpeg and libogg.
But I can't compile libvorbis because configure
insists on creating and running a small test program. This obviously fails, because it creates an armv7
binary, fails to run it, and then interprets this as missing ogg libraries.
How do you usually deal with this kind of problem? I'm tempted to hack the configure script to work around these issues, but because of this kind of failure some features may be disabled. I'm also thinking of letting configure
generate a native Makefile and then convert it to use the iOS toolchain, but this seems too error prone.
Any advice?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您交叉编译任何比 libc (glibc) 具有更多依赖项的东西,它就会变得更加复杂。您需要已经交叉编译了所有依赖项。交叉编译器工具链和所有帮助构建程序和脚本需要知道如何找到这些依赖项(交叉编译的库和标头)。
您需要已经交叉编译了libogg(及其依赖项)并将它们安装到交叉编译根目录中。构建系统中的头文件和库不能用于主机 (arm7) 系统。它们必须分开存放。
另外,如果您想要共享对象库 (*.so) 而不仅仅是静态库,那么就会出现一系列全新的复杂情况。例如,虽然交叉编译器工具链包含交叉编译的 libc 作为工具链的一部分,但您仍然需要主机系统的 libc。作为工具链一部分的 libc 可用于此目的,但其结构方式与主机系统上的不同。有时人们会复制并重新排列文件,但通常人们只是为根目录编译并安装一个新的 glibc。
无论如何,总而言之,您看到的两个错误是因为配置脚本无法找到交叉编译的 libogg 库。如果还没有,您需要交叉编译 libogg (和依赖项)并将它们安装到您的目标根目录中。然后,您需要告诉配置脚本交叉编译的标头(是的,标头是特定于体系结构的)和库位于目标根目录中的位置。通常使用 CFLAGS、LDFLAGS、CXXFLAGS 等(不是 --prefix),但您可能还需要设置其他环境变量来影响 pkg-config 等。构建每个依赖项后,您需要获取makefile 将依赖项安装到根目录。通常这是通过 make DESTDIR=[root] install 完成的,但有些 makefile 有自己的机制(或者没有适当的备用安装机制)。
您可能还需要覆盖某些写得不好并且没有良好的交叉编译默认值的配置检查(使用环境变量)。这些变量通常以 ac_cv_* 开头,
因此基本过程是对您需要的包执行此操作(按依赖顺序):
祝您好运。一旦您对标准交叉编译感到满意,那么您就可以准备好接受真正的黑魔法了,加拿大十字;-)
If you are cross-compiling anything that has more dependencies than libc (glibc) it becomes much more complicated. You need to have already cross-compiled all the dependencies. And the cross-compiler toolchain and all helper build programs and scripts need to know how to find those dependencies (the cross-compiled libraries and headers).
You need to have already cross-compiled libogg (and its dependencies) and installed them into the cross-compile root directory. The headers and libraries from your build system can't be used for the host (arm7) system. They must be kept separate.
Also, if you want to have shared object libraries (*.so) and not just static libraries then there is a whole new set of complications. For example, while a cross-compiler toolchain contains a cross-compiled libc as part of the toolchain, you still need a libc for the host system. The libc that is part of the toolchain can be used for this, but the way it is structured is different than on the host system. Sometimes people copy and re-arrange the files, but often people just compile and install a new glibc for the root.
Anyways, all that to say, the two errors you are seeing are because the configure script is not able to find a cross-compiled libogg library. If you haven't already, you need to cross-compile libogg (and dependencies) and install them into your target root. Then you need to tell the configure script where your cross-compiled headers (yes, header are architecture specific) and libraries are in your target root. Usually using CFLAGS, LDFLAGS, CXXFLAGS, etc (NOT --prefix) but there may be other environment variables you need to set also to affect things like pkg-config, etc. After you have built each dependency, then you need to get the makefile to install the dependency to the root. Usually this is done with
make DESTDIR=[root] install
but some makefiles have their own mechanism (or no proper alternate install mechanism).You may also need to override certain configure checks (using environment variables) that are poorly written and don't have good cross-compile defaults. These variables usually start with ac_cv_*
So the basic process is to do this for packages that you need (in dependency order):
Good luck. Once you feel comfortable with standard cross-compiling, then you will be ready to take on the real black art, the Canadian cross ;-)
我终于想通了。我通过显式使其与 ogg 链接来欺骗
configure
(LDFLAGS="/usr/local/ios/lib/libogg-armv7.a" ./configure ...
)然后从生成的 makefile 中删除对库的显式引用。I finally figured it out. I tricked
configure
by explicitly making it link with ogg (LDFLAGS="/usr/local/ios/lib/libogg-armv7.a" ./configure ...
) and then removed the explicit reference to the library from the generated makefile.