Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID

cURL -- anyone using this with their app?

slycrelslycrel Posts: 34Registered Users
edited August 2009 in iPhone SDK Development
Here are the steps to get this working.

download the distribution of cURL you wish to use. I used this source file from apple.

Download and unzip/untar your source code.
Open the terminal and change to the source directory.
The following command is what I used to compile this, on OS X 10.5.5, with the 2.1 iPhone SDK. You may make changes as desired.

./configure --host=arm-apple-darwin --program-prefix=/usr/local/iphone --disable-shared --disable-crypto-auth --without-gnutls --without-ssl --without-zlib --without-libssh2 --disable-ipv6 --disable-manual --disable-telnet --disable-tftp --disable-ldap --disable-file --disable-ftp CC=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin9-gcc-4.0.1 CFLAGS="-arch armv6 -pipe -std=c99 -Wno-trigraphs -fpascal-strings -fasm-blocks -O0 -Wreturn-type -Wunused-variable -fmessage-length=0 -fvisibility=hidden -miphoneos-version-min=2.0 -gdwarf-2 -mthumb -I/Library/iPhone/include -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.0.sdk" CPP=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/cpp AR=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ar AS=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/as LIBTOOL=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/libtool STRIP=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/strip RANLIB=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ranlib

I think that the libtool line actually doesn't get used, the makefiles use something else in it's place, you can likely remove that portion of the above, but it doesn't hurt anything to leave it. There may be other things like this, but I'm not cool enough to know what's going on there.

One important thing to mention -- you need to use the --host keyword rather than the --build keyword because you are targeting a different architecture than what you are building the library on. This threw me off for a bit.

Once you run this command you should get a bunch of stuff going on and a sort of status screen at the end with a description of what options are on or off in the cURL library you are about to create.

leave the terminal open and go back to the finder, we want to be in the root directory of the folder you unzipped above. Open the lib directory and edit config.h. This file is auto-generated, but we need to change a few lines. Find the following lines and change accordingly:

uncomment #undef HAVE_GLIBC_STRERROR_R
uncomment #undef HAVE_POSIX_STRERROR_R
comment #define HAVE_STRERROR_R 1

Thanks to Denis Laprise for help here.

now save this file and go back to the terminal.

type make and press return. This will compile the library. I was concerned when I did this and spent a few hours trying to figure out what I was doing wrong. You will se a number of ranlib errors about object files that are empty. However, not all object files are empty, this is due to turning off some of the options above. The library itself is built and ranlib is successful on the parts we were building.

This is where I stopped, but if you're more command-line savvy than I you could probably play around with "sudo make install" and get the results handed to you a bit better. I skipped that and grabbed the library to use with my project.

Assuming you used the library I linked, it is in curl-7.16.3/lib/.libs/libcurl.a and is ready to go. if you're still in the terminal you can change to that directory and type "open ." to have a finder window opened for you. Then copy the library to your project folder, along with the curl-7.16.3/include/curl/ directory containing your header files. Include these header files and this library in your project and you're good to go!

keep in mind that THIS WILL NOT WORK IN THE SIMULATOR. It is compiled for the iPhone arm processor and to get curl to work with the simulator you will need to change the paths and --host above in the configure call. I plan on making a copy of my curl source folder, rerunning configure with defaults (which should build for the current platform) and then include that library in my project for the simulator target only. I'll probably also rename the library so that I can tell them apart in the project.

Testing this wasn't too bad either. I used the default template utility iPhone application. Make sure to change the code signing properly so that it works on your device as well as the info.plist to contain your correct information. I used this code to test out the curl library on the iPhone and simply stepped through it in the debugger to verify that it was working.

Thanks again to everyone who helped in this process. I hope this is useful for someone else! =)



Original post:

I've been frustrated by the lack of ability to archive a webpage in a UIWebView when quitting your application to display when restarting it. I've looked around and there seems to be no official way to do this.

I've been looking at cURL and was thinking it would be nice but take me way too long to port this... however, after looking around I found the following path on my HDD:

/Developer/SDKs/iPhoneOS.sdk/Versions/iPhoneOS2.0.sdk/include/curl/curl.h

It should be available with the SDK! Nice!

Oh wait...

Except that I can't find the actual library to include to get this to happen. Nothing in apple's documentation, nothing that I can find in the frameworks or library. Has anyone used cURL with their app and can point me in the right direction? Is there a framework that includes support for this that I am unaware of?

Thanks in advance.
Post edited by slycrel on
«1

Replies

  • erotsppaerotsppa Posts: 357Registered Users Noob
    edited October 2008
  • lapselapse Posts: 211Registered Users
    edited October 2008
  • erotsppaerotsppa Posts: 357Registered Users Noob
    edited October 2008
    lapse: can you post some intrusions on how to get curl working with the iphone sdk, many here will appreciate it!
  • lapselapse Posts: 211Registered Users
    edited October 2008
    ./configure and disable everything. Set the --host appropriately depending if you're configuring for the simulator or the device. Set the CC, CPP, LD, AR, RANLIB environment variables to point to the correct paths for the binutils for the simulator or device.

    Then change around lib/config.h so that POSIX strerror() gets defined and then undef the stuff for r_malloc.
  • slycrelslycrel Posts: 34Registered Users
    edited October 2008
    Thanks for the feedback lapse. I'm just competent enough with ./configure to know I don't know what I am doing, but I can understand some of it. Cross your fingers, I'll post here my results going this route.

    I have heard comments about cURL being included in the SDK, but I've never gotten a good answer, still looking for that one, regardless if I can compile it myself or not. Anyone know the answer to this?
  • slycrelslycrel Posts: 34Registered Users
    edited October 2008
    I've spent some time with configure and I must be doing something worng. Here's what I am passing, trying to do what you've said above, and probably missing something.

    ./configure --build=arm --prefix=/libcurl/ --disable-dependency-tracking --disable-ipv6
    CC=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc
    CPP=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/cpp
    LD=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ld
    AR=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ar
    RANLIB=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ranlib

    I get the following output:
    checking whether to enable maintainer-specific portions of Makefiles... no
    checking for sed... /usr/bin/sed
    checking for ar... /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ar
    checking for a BSD-compatible install... /usr/bin/install -c
    checking whether build environment is sane... yes
    checking for gawk... no
    checking for mawk... no
    checking for nawk... no
    checking for awk... awk
    checking whether make sets $(MAKE)... yes
    checking curl version... 7.16.3
    checking build system type... arm-unknown-none
    checking host system type... arm-unknown-none
    checking for style of include used by make... GNU
    checking for gcc... /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc
    checking for C compiler default output file name...
    configure: error: C compiler cannot create executables
    See `config.log' for more details.

    the config log appears to have this as the relevant portion:

    configure:2926: checking for gcc
    configure:2953: result: /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc
    configure:3191: checking for C compiler version
    configure:3198: /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc --version >&5
    gcc-4.0: installation problem, cannot exec '/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/i686-apple-darwin9-gcc-4.0.1': No such file or directory
    configure:3201: $? = 255
    ...
    configure:3319: error: C compiler cannot create executables

    Did you mean possibly that I should be setting the environment variables outside of configure or something? I'll have to try that.

    I haven't gotten to modifying the .h files as you suggested yet.
  • slycrelslycrel Posts: 34Registered Users
    edited October 2008
    I'm probably talking to myself here, but I may as well document this process for the next poor soul who doesn't know what they are doing just like me.

    I removed the suggested paths for CC and the other env variables and changed them in "Makefile". Now I can get it to configure, but running make doesn't do what I would expect -- it appears to build the object files but I get this when it hits ranlib:

    ranlib: file: .libs/libcurl.a(security.o) has no symbols

    and then a bit later I get this:
    make[1]: Nothing to be done for `all-am'.

    I'll have to check my make file and make sure I got all of the paths changed properly.

    Gotta get some sleep, maybe more progress here tomorrow.

    Still wishing someone would pipe up and give me an easier answer. :D
  • lapselapse Posts: 211Registered Users
    edited October 2008
    Use --host=arm-apple-darwin when running configure.

    You need to make sure ranlib and friends point to the right directory otherwise you will get symbols not found at link time.
  • erotsppaerotsppa Posts: 357Registered Users Noob
    edited October 2008
    so how does this work? Do you compile the library and then include it in Xcode? As well as the header? Can one person just build the library and then share it? Since its the same for everyone?
  • lapselapse Posts: 211Registered Users
    edited October 2008
    Compile it statically and include the .a file as a framework in your XCode project. In the Get Info section for your project, there's a line for 'user defined header paths' or something like that -- point that to the directory holding your curl .h's.
  • erotsppaerotsppa Posts: 357Registered Users Noob
    edited October 2008
  • PhoneyDeveloperPhoneyDeveloper Posts: 1,431Registered Users
    edited October 2008
    What would be best is to build an Xcode project that generates a static lib. You would then add this project to your app project and set the .a file as a dependency. You could then share the project and everything is self contained.

    I don't think anyone here has explained how to build a static lib for the SDK with Xcode. I haven't tried it myself.

    This project seems to build a static lib for the phone but it's makefile driven, I think (I haven't looked at it closely):

    iphone-glu - Google Code
  • slycrelslycrel Posts: 34Registered Users
    edited October 2008
    Thanks for the reply lapse! I'll try a few things later today and let everyone know the results.

    I'm not sure if I'm ambitious enough to write an xcode project for this, we'll see. I'd settle for documenting the process. ;)
  • lapselapse Posts: 211Registered Users
    edited October 2008
    If you google for "iphone curl" there's a blog somewhere that shows the person's ./configure command line. Tweak as necessary for your platform.

    Also keep in mind my previous tips for the paths for ar, ranlib, ld, gcc, etc..
  • slycrelslycrel Posts: 34Registered Users
    edited October 2008
    I finally found that link you're talking about. the trick is learning how to do a google search I guess. if you google "libcurl iPhone" it's the first link. Very helpful.

    I've done a bunch of work to my configure command and while I think I've made the correct changes in the lib/config.h file, I'm still getting no symbols with ranlib, so something's still going wrong.

    this seems to be the problem call here:
    /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ar cru .libs/libcurl.a file.o timeval.o base64.o hostip.o progress.o formdata.o cookie.o http.o sendf.o ftp.o url.o dict.o if2ip.o speedcheck.o ldap.o ssluse.o version.o getenv.o escape.o mprintf.o telnet.o netrc.o getinfo.o transfer.o strequal.o easy.o security.o krb4.o memdebug.o http_chunks.o strtok.o connect.o llist.o hash.o multi.o content_encoding.o share.o http_digest.o md5.o http_negotiate.o http_ntlm.o inet_pton.o strtoofft.o strerror.o hostares.o hostasyn.o hostip4.o hostip6.o hostsyn.o hostthre.o inet_ntop.o parsedate.o select.o gtls.o sslgen.o tftp.o splay.o strdup.o socks.o ssh.o nss.o

    and a sampling of the errors I am getting are here:
    ranlib: file: .libs/libcurl.a(file.o) has no symbols
    ranlib: file: .libs/libcurl.a(ftp.o) has no symbols
    ...
    /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ranlib .libs/libcurl.a
    /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ranlib: file: .libs/libcurl.a(file.o) has no symbols
    /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ranlib: file: .libs/libcurl.a(ftp.o) has no symbols
    ...

    It looks like it's calling a different ranlib first then the one I am specifying later.

    For those following along at home here's where I got my source from:

    http://www.opensource.apple.com/darwinsource/10.5/curl-42/curl-7.16.3.tar.bz2

    And my current command to get this working this far:

    ./configure --host=arm-apple-darwin --program-prefix=/usr/local/iphone --disable-shared --disable-crypto-auth --without-gnutls --without-ssl --without-zlib --without-libssh2 --disable-ipv6 --disable-manual --disable-telnet --disable-tftp --disable-ldap --disable-file --disable-ftp CC=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin9-gcc-4.0.1 CFLAGS="-arch armv6 -pipe -std=c99 -Wno-trigraphs -fpascal-strings -fasm-blocks -O0 -Wreturn-type -Wunused-variable -fmessage-length=0 -fvisibility=hidden -miphoneos-version-min=2.0 -gdwarf-2 -mthumb -I/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.0.sdk/usr/include/libxml2 -I/Library/iPhone/include -I/Users/ghassett/HelloWorld/build/HelloWorld.build/Debug-iphoneos/HelloWorld.build/DerivedSources -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.0.sdk" CPP=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/cpp AR=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ar AS=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/as LIBTOOL=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/libtool STRIP=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/strip RANLIB=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ranlib

    Kind of a mouthful. No wonder I don't use makefiles more often. :D

    If I do manage to get this going I'll edit my top post with the details.

    I better get to work at my "real" job, but I'll do more this evening on this. Thanks for your help so far lapse!
  • lapselapse Posts: 211Registered Users
    edited October 2008
    Look through the Makefiles in lib and src or whatever and make sure that RANLIB, AR, CPP, CC, LD, etc., point to the correct place.

    Tweak the Makefiles and rebuild.
  • slycrelslycrel Posts: 34Registered Users
    edited October 2008
    An update to the cURL thing. The above steps actually WORKED. The ranlib errors I got were appropriate -- those represent the object files that were disabled.

    I have made a simple test application with the code found at this link:

    curl: curl/docs/examples/simple.c

    and it appears to work properly.

    I'll edit my top post to give a more general step by step guide on what I did to get it working in xcode shortly.

    Thanks lapse for pointing me in the right direction and helping me find that blog link!
  • andydamandydam Posts: 2New Users
    edited October 2008
    Just a quick question, where does it save to? Can you specify where it saves to?
  • slycrelslycrel Posts: 34Registered Users
    edited October 2008
    The libcurl.a library? Yeah, I put it in the top post that I edited, I'll paste the relevant portion here:

    Assuming you used the library I linked, it is in curl-7.16.3/lib/.libs/libcurl.a and is ready to go. if you're still in the terminal you can change to that directory and type "open ." to have a finder window opened for you. Then copy the library to your project folder, along with the curl-7.16.3/include/curl/ directory containing your header files. Include these header files and this library in your project and you're good to go!

    Remember, this library only works on the phone, not in the simulator. hope that helps.
  • erotsppaerotsppa Posts: 357Registered Users Noob
    edited October 2008
    slycrel: can I please get your contact, PM me please much appreciated!
  • slycrelslycrel Posts: 34Registered Users
    edited October 2008
    erots, the way to do this is listed in the first post. If you have questions about that I would be happy to answer them here as best I can.
  • andydamandydam Posts: 2New Users
    edited October 2008
    Would any of you mind making an example XCode project for us to see how we are supposed to implent it?
  • malcommalcom Posts: 29Registered Users
    edited October 2008
    I've tried to compile it and it works fine. However I would to have a compiled copy to run inside the simulator. Is it possible?
    (I would add CURLHandle.m/h to iPhone).
  • slycrelslycrel Posts: 34Registered Users
    edited October 2008
    Apple already has a cURL library compiled, you just have to link it in to your simulator project.

    For my app I added both the simulator library and the actual iPhone library to my project as well as the include folder that comes with the curl distribution and everything "just worked". There are probably cleaner ways to do this, but it was pretty fast for me. Do a spotlight search for libcurl and you should find the pre-built library.

    Hope that helps.
  • malcommalcom Posts: 29Registered Users
    edited October 2008
    I cannot found it yet. Can you make to me a simple project? Thanks a lot for your reply :)
«1
Sign In or Register to comment.