交叉编译FreeTDS到iPhone

由于这个问题没有答案,我花了大半个学期,我认为我会发布如何交叉编译FreeTDS 0.91到iPhone ARMv6,ARMv7架构。 这是使用Xcode 4.2和iOS 5 SDK完成的。

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

我也会提到你需要一定的技术水平来尝试这个。 这是一个非常精简的版本,花了我近两个月的时间才弄明白(我把所有不应该做的事情都留给了我)。

其他与此有关的文件:

基本如何使用FreeTDS http://www.freetds.org/userguide/samplecode.htm

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

看到我的答案在下面。

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

对于那些像我这样花费数小时才能find这些标准configuration标志的文档(用于运行./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开发目录中的编译器文件/版本可能有所不同,只需find具有逻辑意义的命名约定。 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 

configurationARM编译(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)运行你的一个脚本。 一次只能编译一个体系结构

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

5)一旦configuration过程完成,你必须破解configuration文件。 打开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找出使用哪个编译文件,请按照这个子步骤来执行dynamic链接。

  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的dynamic链接错误问题的最后一步是进行卸载。 另外,在设备上运行时,还会收到很多警告,以36为增量,关于CPU_SUBTYPE_ARM_ALL被弃用,这是正常的,但是很烦人。

  sudo make uninstall 

我希望这有帮助。

我使用了上面的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 

一个很好的附加function是使用lipinfo将两个静态库合并为一个

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

并将其添加到项目的设置。

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