-1

I want to include curl.h to use the functions included there for my C program and I downloaded them. By them I mean to say .h,.c,.a files i.e. a whole library(curl library). Following is the location to curl.h:

C:\CURL\include\curl

Following is the location to libcurl.a :

C:\CURL\lib

The problem is that I am not able to compile the program correctly as I am thrown error each time.

I tried including path where curl/curl.h resides:

gcc -IC:/CURL/include test.c -o run -lcurl

Error I get:

C:/Program Files (x86)/Embarcadero/Dev-Cpp/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lcurl

collect2.exe: error: ld returned 1 exit status

Thinking opps, I should have given the path to libcurl.a, I tried including path where curl/curl.h resides and path where libcurl.a resides(i don't know if it is corrent to use -I twice):

gcc -IC:/CURL/include -IC:/CURL/lib -lcurl test.c -o run

I was still wrong and Error I get:

C:/Program Files (x86)/Embarcadero/Dev-Cpp/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lcurl

collect2.exe: error: ld returned 1 exit status

I also tried replacing -lcurl with -llibcurl,-llibcurl.a,curl.a while keeping other syntax unchanged for the sake of satisfaction or something like touch and go of if this could be right or that could be right way.

Had I ever entered correct syntax for compiling?

Where am I mistaken in compilation? Please help me in this. Suggest the correct and best way to compile and if possible with makefile.

  • `-L` is for libraries, `-I` is for header files. – 273K Dec 11 '22 at 16:51
  • Does this answer your question? [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – 273K Dec 11 '22 at 16:53
  • @273K, actually I am not getting any `undefined reference` error. I don't know but I guess I am not being able to link library, As I mentioned earlier in the question can you please help me with correct syntax and possibly a `makefile` maybe at bare level. – अनुपम Dec 12 '22 at 14:37
  • @273K, Thanks for your `-L` option. I tried `gcc -IC:/CURL/include -LC:/CURL/lib -lcurl test.c -o run` and it generated error:`skipping incompatible C:/CURL/lib/libcurl.a when searching for -lcurl` – अनुपम Dec 12 '22 at 14:41
  • Try to download the compatible libcurl. – 273K Dec 12 '22 at 14:51
  • I downloaded and now the same command is generating `undefined reference` to certain functions. – अनुपम Dec 12 '22 at 15:31

1 Answers1

0

gcc -IC:/CURL/include test.c -o run -lcurl

If you want to add the path directory to the curl.h, use -I option, but if you want to also link your program, and do it with -lcurl, then you need also to add the path to the library binaries with -Lc:/CURL/lib option.

gcc -IC:/CURL/include test.c -o run -LC:/CURL/lib -lcurl

This will, probably, work as expected.

Luis Colorado
  • 10,974
  • 1
  • 16
  • 31
  • The problem was solved anyway thanks for your effort. Please do check out [this](https://stackoverflow.com/questions/74833527/how-do-i-include-a-needed-c-library-using-gcc-in-visual-studio-code-on-windows?noredirect=1#comment132079616_74833527) and help on that too. – अनुपम Dec 19 '22 at 07:44