lib curl symbol not found

2019-02-13 02:28发布

问题:

Really stupid C question.

I'm trying to build the source code here so I can start on modifying it for myself

http://curl.haxx.se/libcurl/c/ftpget.html

I download the file, then run

gcc -o test ftpget.c

and get

Undefined symbols:
  "_curl_global_init", referenced from:
      _main in ccFchguB.o
  "_curl_easy_perform", referenced from:
      _main in ccFchguB.o
  "_curl_easy_setopt", referenced from:
      _main in ccFchguB.o
      _main in ccFchguB.o
      _main in ccFchguB.o
      _main in ccFchguB.o
  "_curl_easy_cleanup", referenced from:
      _main in ccFchguB.o
  "_curl_easy_init", referenced from:
      _main in ccFchguB.o
  "_curl_global_cleanup", referenced from:
      _main in ccFchguB.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

which makes no sense to me, because

/usr/local/include/curl/curl.h

exists and has these functions. I'm sure this is some basic c compilation thing I'm missing.

Many thanks for any pointers.

回答1:

You need to link with the curl library:

gcc -o test ftpget.c -lcurl