0

How to link this library libcurl statically to the exe? i have tried

--disable-share --enable-static that does not help.

I am using MingW32

Is there an easy way to statically link this library so i can have no more .dlls with my app?

RCECoder
  • 247
  • 1
  • 5
  • 15

3 Answers3

1

If using codeblocks, right click your project and press properties then on the defines tab, add:

CURL_STATICLIB

if using command line then:

-static -static-libgcc -static-libstdc++ -DCURL_STATICLIB -lcurl -lws2_32 -lwinmm

Brandon
  • 22,723
  • 11
  • 93
  • 186
  • If i use this command i get tons of 'undefined reference' to api's in libcurl.a – RCECoder Jan 08 '14 at 20:16
  • I've tried to include `CURL_STATICLIB` in **Preprocessor Definitions**, but it doesn't work. It still requires the libcurl.dll – Sam Oct 12 '20 at 11:07
0

You need to use -static in linker options

72DFBF5B A0DF5BE9
  • 4,954
  • 3
  • 21
  • 24
  • I tried this option but it will not let me compile i get these errors clns.c:(.text+0xad7e): undefined reference to `_imp__curl_e asy_init' clns.c:(.text+0xb1d6): undefined reference to `_imp__curl_e asy_cleanup' clns.c:(.text+0xb6bb): undefined reference to `_imp__curl_e asy_cleanup' clns.c:(.text+0xbc71): undefined reference to `_imp__curl_e asy_cleanup' clns.c:(.text+0xc3bc): undefined reference to `_imp__curl_e asy_init' – RCECoder Jan 08 '14 at 02:47
  • @amaninlove, you need -lcurl also and you need to define curl library path. – 72DFBF5B A0DF5BE9 Jan 08 '14 at 03:06
  • How i can specify the path? isn't setting up a PATH in the environment variable enough? – RCECoder Jan 08 '14 at 20:16
  • Sorry i mean i have copied the lib files of libcurl to Mingw lib directory so specifying the path isn't the problem.I have specified already your command -lcurl still getting the same issue with even more undefined reference like `c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../libcurl.a(md5.o):(.text+0x15): undefined reference to MD5_Init' c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../libcurl.a(md5.o)` . But if i specify the option `-lcurldll` only then it compiles fine but the dll still there not statically linked. – RCECoder Jan 08 '14 at 21:42
  • @amaninlove: gcc -DCURL_STATICLIB -I ../../include -L ../../lib simple.c -o simple -lcurl -lws2_32 -lwinmm – 72DFBF5B A0DF5BE9 Jan 08 '14 at 21:45
  • Thanks i got rid of all errors but still not staticaly linked the `libcurl.dll` is still there, now the problem is there is more dependencies. I can see my app now relying on many .dll files like `zlib1.dll` `LIBEAY32.dll` `libidn-11.dll` `SSLEAY32.dll` `wldap32.dll` What i am doing wrong here? i have also disabled the use of SSL but it still imports them, moreover i am seeing those functions like `curl_easy_cleanup` etc are now turned inside export directory. – RCECoder Jan 08 '14 at 23:05
  • And here is the command-line i am using `CFLAGS="-O2 -static -DCURL_STATICLIB -DHTTP_ONLY -lcurl -lcurldll -lrtmp -lcrypto -lidn -lssl -lws2_32 -lwinmm -Izlib -lwldap32 -lz -leay32 -lpthread -msse2" ./configure` – RCECoder Jan 08 '14 at 23:07
  • 1
    no ideas, see: http://fatchoco.wordpress.com/2009/03/01/using-curl-in-mingw/ – 72DFBF5B A0DF5BE9 Jan 09 '14 at 00:28
0

Here is the steps how to do that. but you may get some additional errors. those are need to figure out by yourself. This is Just a guidance.

  1. You should have two project in Visual Studio Solution

    • libcurl project (source code downloaded from curl web. this may help you for this)
    • your project
  2. Build libcurl as a static lib.(right click libcurl project in solution explorer -> properties -> configuration properties -> General-> change configuration Type to Static Library (.lib))

  3. Then right click your project go to propertied ->configuration properties ->Linker -> general

  4. In "additional Library directories" add the path to above curl.lib.

  5. then go to propertied ->configuration properties ->Linker -> input
  6. add libcurl.lib name to additional dependencies.
  7. then go to properties -> configuration properties -> General
  8. If your project uses MFC or ATL change use of MFC and use of ATL to use MFC in static library and use ATL in static library accordingly.
  9. then build the solution.
  10. Enjoy libcurl :)
Nayana Adassuriya
  • 23,596
  • 30
  • 104
  • 147