curl / Mailing Lists / curl-library / Single Mail


Undefined Reference Error when Linking .OBJ file

From: Dan Gribble via curl-library <>
Date: Thu, 4 Apr 2019 15:39:30 +0000

Hi, I am very new to C++ and using i'm cURL to connect to UK HMRC hello world API.

Using the cURL commandline application I can get the desired JSON hello world response, however, when attempting to link after compiling (using open Watcom 1.9) a simple test.cpp file on Windows 7, I get the following errors:

Error! E2028: curl_slist_append_ is an undefined reference
Error! E2028: curl_easy_init_ is an undefined reference
Error! E2028: curl_easy_setopt_ is an undefined reference
Error! E2028: curl_easy_perform_ is an undefined reference
Error! E2028: curl_easy_cleanup_ is an undefined reference
Error! E2028: curl_slist_free_all_ is an undefined reference

My C++ source is as follows:

#include <curl/curl.h>

int main(int argc, char *argv[])
  CURLcode ret;
  CURL *hnd;
  struct curl_slist *slist1;

  slist1 = NULL;
  slist1 = curl_slist_append(slist1, "Accept: application/vnd.hmrc.1.0+json");

  hnd = curl_easy_init();
  curl_easy_setopt(hnd, CURLOPT_BUFFERSIZE, 102400L);
  curl_easy_setopt(hnd, CURLOPT_URL, "");
  curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 1L);
  curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, slist1);
  curl_easy_setopt(hnd, CURLOPT_USERAGENT, "curl/7.64.0");
  curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L);
  curl_easy_setopt(hnd, CURLOPT_HTTP_VERSION, (long)CURL_HTTP_VERSION_2TLS);
  curl_easy_setopt(hnd, CURLOPT_HTTP09_ALLOWED, 1L);
  curl_easy_setopt(hnd, CURLOPT_CAINFO, "C:\\oem\\curl\\curl-7.64.0-win32-mingw\\bin\\curl-ca-bundle.crt");
  curl_easy_setopt(hnd, CURLOPT_SSH_KNOWNHOSTS, "C:\\DJG/_ssh/known_hosts");
  curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "GET");
  curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L);

  ret = curl_easy_perform(hnd);

  hnd = NULL;
  slist1 = NULL;

  return (int)ret;

Using the -DWIN32 and -DCURL_STATICLIB on my compile command prior to linking doesn't seem to make any difference. I understand you may think this is more of a compile/link problem rather than a specific cURL problem, but I would be grateful if anyone could offer any advice or point me in the right direction of where I can find the answer. Am I missing any specific files or libraries that need to be included when compiling or linking?

Thank you.

Received on 2019-04-04