【问题标题】:Cross compiling FreeTDS to iPhone将 FreeTDS 交叉编译到 iPhone
【发布时间】:2012-07-10 14:38:42
【问题描述】:

由于这个问题没有答案,而且我花了一个学期的大部分时间来解决这个问题,我想我会发布如何将 FreeTDS 0.91 交叉编译到 iPhone ARMv6、ARMv7 架构。这是使用 Xcode 4.2 和 iOS 5 SDK 完成的。

之所以问这个问题,是因为您正在为需要连接到 Mircosoft SQL Sever 的 iOS 设备开发应用程序,这需要使用 Microsoft 专有的表格数据流 (TDS) 协议。

我还要提到,您需要一定程度的技术技能才能尝试此操作。这是我花了将近两个月才弄清楚的一个非常浓缩的版本(我留下了所有你不应该做的事情)。

与此相关的其他文档:

使用 FreeTDS 的基本方法http://www.freetds.org/userguide/samplecode.htm

Microsoft 的 TDS API 文档 http://msdn.microsoft.com/en-us/library/aa936985(v=sql.80)

请看下面我的回答。

另请参阅 Xcode 4.5 更新文件的 saskathex 答案。

【问题讨论】:

  • 这太棒了!但我最终使用了 mobilefoo 的 iSQL SDK。
  • @AmigableClarkKant 这样会更有意义,不是吗。

标签: iphone ios xcode4.2 cross-compiling freetds


【解决方案1】:

对于像我这样需要花费数小时查找这些标准配置标志(用于运行 ./configure make make install)文档的人

        ./configure --build is used for specifing the architecture you want to complie for
        ./configure --host is used to specify the ark of the machine doing the compileing (running xcode)
        ./configure --target seems to be an alias

现在开始解决问题。

1) 获取最新版本的 FreeTDS http://www.freetds.org/

2) 下一步是制作您自己的 bash shell 文件,以正确运行 FreeTDS ./configure。您将需要两个,因为模拟器是 i386/i686 架构,而苹果设备(iPhone、iPod 等)是 ARM 架构。此外,您在 iPhone 开发目录中的编译器文件/版本可能会有所不同,只需找到合乎逻辑且具有相似命名约定的内容即可。 mac 主机架构由命令 uname -p 提供。

这是我在模拟器 (i386) build_for_simulator_i386.sh 上使用的构建示例:

 #!/bin/sh

 #unset some shell variables
 unset CC
 unset CFLAGS
 unset CPP

 export buildPath=`pwd`

 # make i386 (Simulator) target
 export CC=/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/i686-apple-darwin11-llvm-gcc-4.2

 export CFLAGS="-isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk"

 # if you want Windows Authentication (NTLM) support you must use at least tds version 7
 # the default is 5
 ./configure --build=i386 --host=i386 --target=i386 --with-tdsver=7.1 

ARM编译配置示例(build_for_device_armv7.sh):

 #!/bin/sh

 # unset some shell variables
 unset CC
 unset CFLAGS
 unset CPP

 export buildPath=`pwd`

 # make arm target
 export CC=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin10-llvm-gcc-4.2

 export CFLAGS="-isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk"

 export CPP=/usr/bin/cpp


 ./configure --build=arm-apple-darwin10 --host=x86_64-apple-darwin11.3.0 --target=armv7 --with-tdsver=7.1

3) 下一个 cd 到解压 freetds 下载的根 freetds 目录,我的是 freetds_0.91

4) 运行您的脚本之一。您一次只能编译 ONE 架构

 sh build_for_(desiered build)  
        this runs ./configure for you with the correct options
        (tds version 7 required for NTLM authentication)

5) 配置过程完成后,您必须破解配置文件。打开 freetds_0.91/include/config.h 然后在第 172 行将 #define HAVE_ICONV 1 更改为 #define HAVE_ICONV 0

6) 如果您之前运行过 ./configure、make、make install 然后运行这些命令。特别是如果您的切换架构不这样做会导致运行 make 时出错

    sudo make clean
    sudo make uninstall

7) 使用 make 执行编译

    make all
    sudo make install

make 过程会故意出现一些错误,但是如果你在 shell 提示符的六七行内看到错误,一旦它返回,你就有问题,需要在继续之前修复它们。让我们说在这一点上很多事情都可能出错。

8) 安装二进制编译文件后,它是 freetds 制作的所有小 .o 文件的顶点 /usr/local/lib/libsybdb.a 相信我,你不想要为您想要的库提取 .o 文件。将 /usr/local/lib/libsybdb.a 复制到项目中的相应文件夹。我所做的是有两个单独的文件夹,每个架构一个,命名为“compiled_freetds-0.91_simulator_i386”和“compiled_freetds-0.91_device_armv7”。

9) 由于您想让您的生活更轻松,并让 xcode 确定要使用哪个编译文件,请按照此步骤子集执行动态链接。

 a) Select you project settings on the left had side of xcode 
 (the blue think with the name of your project on it)

 b) Select the Target (usual the same name as your app) 

 c) Navigate to **build settings**, scroll down to **linking > other linker flags**

 d) On the left side of Other Linker Flags a mouse over will reveal an expander,    
 expanding will reveal Debug and Release rows.

 e) Add the appriate architectures by selecting the plus on the right side of 
 either Debug or Release.  When the new row appears select the architecture, 
 double click the first editable field from the right to open  an entry box 
 that you can then drag the appropriate  complied file into it to be dynamically     
 linked.  You must do this for both files and when done correctly the file 
 under ARMv7 will be used when building for the device and the one for Any iOS   
 Simulator SDK will be used when running on the simulator.
 **Note:** You may also need to add the -all_load flag to resolve linking issues.

10) 在设备上运行代码时,似乎可以避免涉及 libsybdb.5.dylib 的动态链接错误问题的最后一步是进行卸载。此外,在设备上运行时,您还会收到很多警告,以 36 为增量,关于 CPU_SUBTYPE_ARM_ALL 已被弃用,这很正常,但很烦人。

    sudo make uninstall  

我希望这会有所帮助。

【讨论】:

  • 我知道您为此投入了大量工作,所以很遗憾地告诉您,但是您混淆了 ./configure 的 --build 和 --host 参数用法。反之亦然,否则我误解了你的解释。请参阅此评论末尾的链接,它很好地解释了它。并且 --target 不是别名,而是仅在构建工具链时使用,例如编译器或调试器 - 例如在编译编译器时。对于其他任何事情, --target 都无关紧要。 stackoverflow.com/questions/5139403/… ;祝你好运,玩得开心!
【解决方案2】:

我使用了上述 bash 文件,但从 XCode 4.5 开始,开发者工具位于应用程序包中。所以我修改了脚本以使用我的 MacOS Lion 和当前 XCode 版本“4.5.2 (4G2008a)”运行

build_for_simulator_i386.sh:

#!/bin/sh

# unset some shell variables
unset CC
unset CFLAGS
unset CPP

# make i386 (Simulator) target
export CC=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/i686-apple-darwin11-llvm-gcc-4.2
export CFLAGS="-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.0.sdk"
export CPP=/usr/bin/cpp

./configure -build=i686-apple-darwin11 --host=i686-apple-darwin11 --target=i686-apple-darwin11 --with-tdsver=7.1

build_for_device_armv7.sh:

#!/bin/sh

# unset some shell variables
unset CC
unset CFLAGS
unset CPP

# make arm target
export CC=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin10-llvm-gcc-4.2
export CFLAGS="-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk"
export CPP=/usr/bin/cpp

./configure --build=arm-apple-darwin10 --host=x86_64-apple-darwin11 --target=armv7 --with-tdsver=7.1

一个不错的插件是使用lipinfo将两个静态库合并为一个

lipo compiled_freetds-0.91_device_armv7/libsybdb.a compiled_freetds-0.91_simulator_i386/libsybdb.a -create -output universal_libsybdb.a

只需将其添加到项目的设置中即可。

想分享一下,因为上面的脚本为我节省了很多时间。

【讨论】:

    猜你喜欢
    • 2010-10-07
    • 2010-12-08
    • 1970-01-01
    • 2011-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-09
    • 2021-05-03
    相关资源
    最近更新 更多