Tri*_*tan 32 iphone cross-compiling freetds ios xcode4.2
由于这个问题没有答案,我花了大部分时间来计算它,我想我会发布如何将FreeTDS 0.91交叉编译为iPhone ARMv6,ARMv7架构.这是使用Xcode 4.2和iOS 5 SDK完成的.
之所以要问这个问题,是因为您正在为需要连接到Mircosoft SQL Sever的iOS设备开发应用程序,这需要使用Tabular Data Stream(TDS)协议,因为它是Microsoft专有的.
我还要提到你需要一定程度的技术才能尝试这一点.这是我花了将近两个月才弄明白的一个非常简洁的版本(我留下了你不应该做的所有事情).
与此有关的其他文件:
基本如何使用FreeTDS http://www.freetds.org/userguide/samplecode.htm
Microsoft的TDS API文档 http://msdn.microsoft.com/en-us/library/aa936985(v=sql.80)
请参阅下面的答案.
另请参阅saskathex回答Xcode 4.5更新的文件.
对于像我这样需要花费数小时查找这些标准配置标志的文档的人(用于运行 ./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
Run Code Online (Sandbox Code Playgroud)
现在就来解决问题了。
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
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
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)
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
7) 使用make进行编译
make all
sudo make install
Run Code Online (Sandbox Code Playgroud)
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.
Run Code Online (Sandbox Code Playgroud)
10) 最后一步似乎可以避免在设备上运行代码时涉及 libsybdb.5.dylib 的动态链接错误问题,即进行卸载。此外,当在设备上运行时,您还会收到大量关于 CPU_SUBTYPE_ARM_ALL 已弃用的警告(增量为 36),这是正常的,但很烦人。
sudo make uninstall
Run Code Online (Sandbox Code Playgroud)
我希望这有帮助。