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.
Replies
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeThen change around lib/config.h so that POSIX strerror() gets defined and then undef the stuff for r_malloc.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeI 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?
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome./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.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeI 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
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeYou need to make sure ranlib and friends point to the right directory otherwise you will get symbols not found at link time.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeI 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
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeI'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. ;)
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeAlso keep in mind my previous tips for the paths for ar, ranlib, ld, gcc, etc..
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeI'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!
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeTweak the Makefiles and rebuild.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeI 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!
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeAssuming 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.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome(I would add CURLHandle.m/h to iPhone).
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeFor 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.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome