2012-07-11 92 views
32

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

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

我还会提到你需要某种程度的技术技能才能尝试这个。这是一个非常精简的版本,花了我近两个月的时间才弄清楚(我遗留了所有你不应该做的事情)。

与本其它文档

基本 http://msdn.microsoft.com/en-us/library/aa936985(v=sql.80)

如何使用freetds的http://www.freetds.org/userguide/samplecode.htm

微软的TDS API文档上见我的回答如下。

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

+1

这太好了!但我最终通过mobilefoo使用了iSQL SDK。 – Hackmodford 2012-11-04 05:31:12

+0

@AmigableClarkKant这会让事情变得更有意义。 – Tristan 2012-11-16 02:49:59

回答

4

对于那些像我这样将花费数小时寻找文档,这些标准配置的标志(用于运行的./configure使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)下一步是使正常运行freetds的的./configure自己的bash shell文件。你需要两个,因为模拟器是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)运行你的一个脚本。你只能在一个时间

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

5)一旦配置过程完成后,你必须破解的配置文件编译ONE架构。开freetds_0.91 /包含/然后在管线172变化的#define HAVE_ICONV 1的#define HAVE_ICONV 0

6)如果先前运行的config.h。/ configure,make,make install然后运行这些命令。特别是如果你的交换架构,你会得到运行错误,让没有做这个

sudo make clean 
    sudo make uninstall 

7)执行使用编译使

make all 
    sudo make install 

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

8)安装二进制文件符合这是所有的小.o文件的是freetds的是使/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 

我希望这会有所帮助。

+0

我知道你把大量的工作放在这里,所以我很遗憾地告诉你,但是你的.build和--host参数用于./configure。反之亦然,否则我误解了你的解释。请参阅此评论末尾的链接,这很好地解释了它。而--target不是别名,而是仅在构建工具链时才使用,例如编译器或调试器 - 例如当你编译一个编译器时。对于其他的东西,--target是无关紧要的。 http://stackoverflow.com/questions/5139403/whats-the-difference-of-configure-option-build-host-and-target;祝你好运,玩得开心! – 2014-10-22 01:03:17

3

我使用了上述bash文件,但自XCode 4.5开发人员工具在应用程序包中。所以我修改我的MacOS狮子和当前的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 

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

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