Using libcurl on iOS 5 as an alternative to NSURLConnection

后端 未结 7 2061
栀梦
栀梦 2021-02-01 10:01

Update: NSURLConnection now seems to properly support 100-Continue. In any case, this answer contains a link to the script to build libcurl for iOS/OSX.

I\'m ha

7条回答
  •  半阙折子戏
    2021-02-01 10:23

    The problem is:

    C compiler cannot create executables
    

    The reason:

    Your C compiler for iOS, arm-apple-darwin9-gcc, is a cross-compiler: it runs on a PC, but generates code for iDevices. Thus, it can't use the computer's native programming resources (libraries, header files). You have to tell it where to find iOS's own headers and libraries. You can do it by passing it the -isysroot=/path/to/iOS_SDK/ option. For example, the following won't work out of the box:

    /path/to/arm-apple-darwin10-gcc hello.c -o hello
    

    But the following will:

    /path/to/arm-apple-darwin10-gcc -isysroot /Developer/Platforms/iPhoneOS.platform/SDKs/iPhoneOS5.0.1.sdk hello.c -o hello
    

    I don't use Xcode, neither do I have a Mac, so I don't know the exact location of the iOS toolchain sysroot, but it might be something like the one in the above command.

    And how to use all this with configure? Well, you have 3 compilation stages: preprocessing, compiling and linking. SO you have to tell the preprocessor and the compiler where can it find the headers, and the linker where can it find the libraries. (Particularily, you have to forget to tell the preprocessor where your sysroot is). So do something like this:

    export CC=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/llvm-gcc-4.2
    export CFLAGS="-arch armv7 -isysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk"
    export CPPFLAGS="-isysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk"
    export LDFLAGS="-arch armv7 -isysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk"
    export CPP=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/llvm-cpp-4.2
    export AR=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ar
    ./configure --disable-shared --without-ssl --without-libssh2 --without-ca-bundle --without-ldap --disable-ldap --host=arm-apple-darwin10 --build=arm-apple-darwin10
    make
    sudo make install
    

提交回复
热议问题