将FreeTDS交叉编译到iPhone

32

由于这个问题没有答案,我花了大部分学期的时间去解决它,所以我想发帖说明如何将FreeTDS 0.91交叉编译到iPhone ARMv6、ARMv7架构中。这是使用Xcode 4.2和iOS 5 SDK完成的。

之所以会问这个问题,是因为您正在为需要连接到Mircosoft SQL Server的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文件。


1
太好了!但是最终我使用了 mobilefoo 的 iSQL SDK。 - Hackmodford
@AmigableClarkKant 那样做会更有意义,不是吗。 - Tristan
2个回答

4

对于像我这样的人,会花费数小时查找这些标准配置标志的文档(用于运行./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)下一步是创建正确运行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_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) 配置过程完成后,您需要修改配置文件。打开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

制作过程有意引发一些错误,但如果您在 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都是无关紧要的。祝你好运并玩得开心! - Daniel S.

3

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

只需将此内容添加到项目设置中即可。

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接