【问题标题】:Compiling FreeType for iPhone?为 iPhone 编译 FreeType?
【发布时间】:2016-12-05 16:03:43
【问题描述】:

我在 Windows、Linux 和 OSX 上使用 FreeType 没有任何问题,现在我要把我的技术移植到 IOS... 而且我找不到为它编译 FreeType 的方法。

起初我尝试将每个 FT 文件都放入我的项目中,但这显然不起作用。

然后我尝试在this tutorial here 之后创建一个静态库。 虽然我无法测试它是否适用于 arm 目标,但它不适用于模拟器目标。

当试图将构建的库链接到 XCode 时,它​​显示“libfreetype-simulator.a,文件是为存档而构建的,它不是被链接的体系结构 (i386)” 没关系,因为命令“lipo -info libfreetype-simulator.a”告诉我该文件是为 x86_64 构建的。 我尝试使用“./configure --i386-apple-darwin”,here's the log 对其进行配置。 但是,生成的拱门仍然是 x86_64。

我该如何为 i386、iphone 模拟器构建 freetype? 我真的一点头绪都没有。

【问题讨论】:

标签: iphone ios config freetype


【解决方案1】:

我使用了link in cxa's answer。但是它已经过时了,我的配置行不适合评论。对于 armv7,使用 6.1 SDK 编译,最低版本为 5.1,没有 bzip2,您需要类似:

./configure '--without-bzip2' '--prefix=/usr/local/iphone' '--host=arm-apple-darwin' '--enable-static=yes' '--enable-shared=no' 'CC=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc' 'CFLAGS=-arch armv7 -pipe -std=c99 -Wno-trigraphs -fpascal-strings -O2 -Wreturn-type -Wunused-variable -fmessage-length=0 -fvisibility=hidden -miphoneos-version-min=5.1 -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/usr/include/libxml2/ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/' 'AR=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ar' 'LDFLAGS=-arch armv7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/ -miphoneos-version-min=5.1'

请注意缺少-mdynamic-no-pic,否则会产生链接器警告,如果留在其中,还会收到来自 Apple 的警告电子邮件。另请注意,各种路径名已更改。

【讨论】:

【解决方案2】:

我今天在尝试为 iOS 编译 FreeType 时遇到了这个项目:https://github.com/cdave1/freetype2-ios

只需下载,在 xcode 中打开,然后编译。 :)

希望这对尝试为 iOS 编译的其他人有所帮助。

【讨论】:

    【解决方案3】:

    对于 Xcode 5,gcc 已移动位置,因此配置应为:

    ./configure --without-zlib --without-png --without-bzip2 '--prefix=/usr/local/iPhone' '--host=arm-apple-darwin' '--enable-static=yes' '--enable-shared=no' 'CC=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang' 'CFLAGS=-arch armv7 -pipe -std=c99 -Wno-trigraphs -fpascal-strings -O2 -Wreturn-type -Wunused-variable -fmessage-length=0 -fvisibility=hidden -miphoneos-version-min=6.1 -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/usr/include/libxml2/ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/' 'AR=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ar' 'LDFLAGS=-arch armv7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/ -miphoneos-version-min=6.1'
    

    可以通过运行找到CC的位置:

    $ xcrun -find -sdk iphoneos clang
    

    【讨论】:

      【解决方案4】:

      对于在 Xcode 6.1 上最小目标为 7.1 的 iOS SDK 8.1,此方法有效:

      ./configure --without-zlib --without-png --without-bzip2 '--prefix=/usr/local/iPhone' '--host=arm-apple-darwin' '--enable-static=yes' '--enable-shared=no' 'CC=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang' 'CFLAGS=-arch armv7 -pipe -std=c99 -Wno-trigraphs -fpascal-strings -O2 -Wreturn-type -Wunused-variable -fmessage-length=0 -fvisibility=hidden -miphoneos-version-min=7.0 -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk/usr/include/libxml2/ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk/' 'AR=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ar' 'LDFLAGS=-arch armv7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk/ -miphoneos-version-min=7.0'
      

      【讨论】:

      • 非常感谢!它为我节省了大量时间!
      【解决方案5】:

      也许有人会觉得它很有用。
      SDK 8.1,XCode 6.1
      i386,x86_64,arm64(用于分析),armv7,armv7s

      ./configure CFLAGS="-arch i386"
      make clean
      make
      cp objs/.libs/libfreetype.a libfreetype-i386.a
      
      ./configure CFLAGS="-arch x86_64"
      make clean
      make
      cp objs/.libs/libfreetype.a libfreetype-x86_64.a
      
      ./configure --without-zlib --without-png --without-bzip2 '--prefix=/usr/local/iPhone' '--host=arm-apple-darwin' '--enable-static=yes' '--enable-shared=no' 'CC=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang' 'CFLAGS=-arch armv7 -pipe -std=c99 -Wno-trigraphs -fpascal-strings -O2 -Wreturn-type -Wunused-variable -fmessage-length=0 -fvisibility=hidden -miphoneos-version-min=7.0 -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk/usr/include/libxml2/ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk/' 'AR=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ar' 'LDFLAGS=-arch armv7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk/ -miphoneos-version-min=7.0'
      make clean
      make
      cp objs/.libs/libfreetype.a libfreetype-armv7.a
      
      ./configure --without-zlib --without-png --without-bzip2 '--prefix=/usr/local/iPhone' '--host=arm-apple-darwin' '--enable-static=yes' '--enable-shared=no' 'CC=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang' 'CFLAGS=-arch arm64 -pipe -std=c99 -Wno-trigraphs -fpascal-strings -O2 -Wreturn-type -Wunused-variable -fmessage-length=0 -fvisibility=hidden -miphoneos-version-min=7.0 -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk/usr/include/libxml2/ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk/' 'AR=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ar' 'LDFLAGS=-arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk/ -miphoneos-version-min=7.0'
      make clean
      make
      cp objs/.libs/libfreetype.a libfreetype-arm64.a
      
      ./configure --without-zlib --without-png --without-bzip2 '--prefix=/usr/local/iPhone' '--host=arm-apple-darwin' '--enable-static=yes' '--enable-shared=no' 'CC=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang' 'CFLAGS=-arch armv7s -pipe -std=c99 -Wno-trigraphs -fpascal-strings -O2 -Wreturn-type -Wunused-variable -fmessage-length=0 -fvisibility=hidden -miphoneos-version-min=7.0 -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk/usr/include/libxml2/ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk/' 'AR=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ar' 'LDFLAGS=-arch armv7s -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk/ -miphoneos-version-min=7.0'
      make clean
      make
      cp objs/.libs/libfreetype.a libfreetype-armv7s.a
      
      lipo -create -output libfreetype.a libfreetype-i386.a libfreetype-x86_64.a libfreetype-armv7.a libfreetype-armv7s.a libfreetype-arm64.a 
      

      【讨论】:

        【解决方案6】:

        This shell script 为我工作,x86_64。你可能需要看看。

        我用它编译freetype2.5.5,得到了armv7、arm64、i386、x86_64。当然它是一个单独的胖静态库。

        【讨论】:

        • 谢谢!截至 2015 年 9 月,您的答案似乎是唯一剩余的可行解决方案
        【解决方案7】:

        为了使 freetype 顺利编译,将变量 'CC'、'CFLAGS'、'LDFLAGS' 和 'AR' 作为参数传递给 configurenot 作为环境变量非常重要。 p>

        在某些时候configure 运行机器的本机 gcc,如果您有指向 iphone SDK 的“LDFLAGS”,它将导致它失败。将变量传递给configure 似乎可以解决这个问题。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2016-11-19
          • 2014-09-10
          • 1970-01-01
          • 1970-01-01
          • 2011-02-14
          • 1970-01-01
          • 1970-01-01
          • 2010-11-21
          相关资源
          最近更新 更多