PDA

View Full Version : C download function?



Levo
October 19th, 2009, 09:40 PM
Hi! I am making a program using C. I need a way to download files from the net. I searched but I didn't found anything. I don't want to use wget. Thanks in advance!

dwhitney67
October 19th, 2009, 09:44 PM
Consider libcurl.

P.S. Go here to view some example programs. http://curl.haxx.se/libcurl/c/example.html

openfly
October 19th, 2009, 09:57 PM
Just want to chime in seconding curl. libcurl knowledge is pretty transferable from all languages so you'll be learning something basic and useful all over the place.

Levo
October 20th, 2009, 10:54 AM
Consider libcurl.

P.S. Go here to view some example programs. http://curl.haxx.se/libcurl/c/example.html

yes i tried libcurl before posting, but it didn't compile.

JordyD
October 20th, 2009, 10:57 AM
yes i tried libcurl before posting, but it didn't compile.

Isn't libcurl in the repos?

Levo
October 20th, 2009, 11:29 AM
Isn't libcurl in the repos?

I weren't clear. I want to compile it under windblows using devc++.

Zugzwang
October 20th, 2009, 11:40 AM
Should be no problem to compile libcurl in DevC++. You can also try the already compiled versions for windows from libcurl's homepage.

Probably this is your problem: http://pidgin.im/pipermail/devel/2009-February/007571.html

Levo
October 20th, 2009, 11:59 AM
Should be no problem to compile libcurl in DevC++. You can also try the already compiled versions for windows from libcurl's homepage.

Probably this is your problem: http://pidgin.im/pipermail/devel/2009-February/007571.html

Yes that's it. But where to run the command described? And the file "makefile.mingw" doesn't exist. I tried adding "-L"C:/Dev-Cpp/lib/curl"" in makefile.win, but nothing changed.

Levo
October 20th, 2009, 01:05 PM
What I want to do is to compile the curl headers in my program (no external library).

dwhitney67
October 20th, 2009, 01:16 PM
What I want to do is to compile the curl headers in my program (no external library).

Header files are always compiled. If the header files declare functions, these functions must be implemented somewhere if they are going to be used.

libcurl is a collection of header files and both shared-object library and static library files.

Obviously to reference the correct syntax for a libcurl function, you will need to include the header file which declares the function.

When it is time to link your application to form the executable, you have two choices: link with the shared-object libraries, or link with the static libraries. Typically one does not build these libraries when the application is built.

If you link with the shared-object libraries, then your app will have a small-footprint on the hard-disk, because during runtime it will automatically reference the necessary shared-object library as needed.

If you are looking to create an application that can be moved from one (similar) machine to another, without having to worry if libcurl is present or not, then you would link your application with the static libraries. Bear in mind that this will significantly increase the footprint size of the application.

Either way, if you develop under Windows, the executable will not run under Linux, unless 1) you recompile the source, or 2) you run it under a Windows Emulator (eg wine).

Levo
October 20th, 2009, 01:21 PM
Header files are always compiled. If the header files declare functions, these functions must be implemented somewhere if they are going to be used.

libcurl is a collection of header files and both shared-object library and static library files.

Obviously to reference the correct syntax for a libcurl function, you will need to include the header file which declares the function.

When it is time to link your application to form the executable, you have two choices: link with the shared-object libraries, or link with the static libraries. Typically one does not build these libraries when the application is built.

If you link with the shared-object libraries, then your app will have a small-footprint on the hard-disk, because during runtime it will automatically reference the necessary shared-object library as needed.

If you are looking to create an application that can be moved from one (similar) machine to another, without having to worry if libcurl is present or not, then you would link your application with the static libraries. Bear in mind that this will significantly increase the footprint size of the application.

Either way, if you develop under Windows, the executable will not run under Linux, unless 1) you recompile the source, or 2) you run it under a Windows Emulator (eg wine).

My problem is that I cannot link the static libraries. I don't know how. And I cannot find anything searching the web.

dwhitney67
October 20th, 2009, 01:40 PM
My problem is that I cannot link the static libraries. I don't know how. And I cannot find anything searching the web.

Under Linux, one would do something like:


gcc MySource.c -static -lcurl -o myapp

I do not know what the construct is under Windows. IMO, Windows are great to look out of, but not for computing.

shae
October 20th, 2009, 04:28 PM
If you cannot get libcurl to work in windows, you can implement your own downloader with sockets. Here is a good introduction: http://beej.us/guide/bgnet/.

interval1066
October 20th, 2009, 04:34 PM
What I want to do is to compile the curl headers in my program (no external library).

When you say "DevC++" are you talking Microsoft Developer's Studio? May not be as strait forward as you are attempting. I would look for a Win32 (or 64) version of libcurl (may not exist, but it may) targeting DevStudio, or just develop your app on cygwin, which is not a bad way to go. You know you can develop apps with cygwin and re-distribute the cygwin dll with your monstrous creations. At least I believe you can, I think there's a permission slip somewhere in the cygwin readmes.

Levo
October 20th, 2009, 06:04 PM
If you cannot get libcurl to work in windows, you can implement your own downloader with sockets. Here is a good introduction: http://beej.us/guide/bgnet/.

I don't make this program for me, so I'd prefer an easiest way.

Dev-C++ http://www.bloodshed.net/

Levo
October 21st, 2009, 01:13 PM
OK, I fixed the problem with the linker options. But when I download a file that is more than 1-2 megabytes it is always corrupted. Does anybody know anything about this?