title: C: Post json data using HTTP requests
body: <p>I am trying to post json data to a server through an URL using C. I have downloaded the curl.h package from <code>https://curl.se/download.html</code> and has included it in the code. This is what I have done:</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &quot;F:\Desktop\myfolder\curl\include\curl\curl.h&quot;
  
  int main (int argc, char *argv[]) {
      CURL *curl;
      CURLcode res;
  
      curl_global_init(CURL_GLOBAL_ALL);
      curl = curl_easy_init();
      if (curl == NULL) {
          return 128;
      }
  
      char* jsonObj = &quot;{ \&quot;name\&quot; : \&quot;ABC\&quot; , \&quot;age\&quot; : \&quot;22\&quot; }&quot;;
  
      struct curl_slist *headers = NULL;
      curl_slist_append(headers, &quot;Accept: application/json&quot;);
      curl_slist_append(headers, &quot;Content-Type: application/json&quot;);
      curl_slist_append(headers, &quot;charset: utf-8&quot;);
  
      curl_easy_setopt(curl, CURLOPT_URL, &quot;http://ip-address/myapi/&quot;);
  
      curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, &quot;POST&quot;);
      curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
      curl_easy_setopt(curl, CURLOPT_POSTFIELDS, jsonObj);
      curl_easy_setopt(curl, CURLOPT_USERAGENT, &quot;libcrp/0.1&quot;);
  
      res = curl_easy_perform(curl);
  
      curl_easy_cleanup(curl);
      curl_global_cleanup();
      return res;
  }
  </code></pre>
  <p>Unfortunately, I am getting the following error:</p>
  <pre><code>C:\Users\Admin\AppData\Local\Temp\ccoDiLJ0.o:gpsapi.c:(.text+0xee): undefined reference to `__imp_curl_global_init'
  C:\Users\Admin\AppData\Local\Temp\ccoDiLJ0.o:gpsapi.c:(.text+0xf7): undefined reference to `__imp_curl_easy_init'
  C:\Users\Admin\AppData\Local\Temp\ccoDiLJ0.o:gpsapi.c:(.text+0x136): undefined reference to `__imp_curl_slist_append'
  C:\Users\Admin\AppData\Local\Temp\ccoDiLJ0.o:gpsapi.c:(.text+0x14d): undefined reference to `__imp_curl_slist_append'
  C:\Users\Admin\AppData\Local\Temp\ccoDiLJ0.o:gpsapi.c:(.text+0x164): undefined reference to `__imp_curl_slist_append'
  C:\Users\Admin\AppData\Local\Temp\ccoDiLJ0.o:gpsapi.c:(.text+0x185): undefined reference to `__imp_curl_easy_setopt'
  C:\Users\Admin\AppData\Local\Temp\ccoDiLJ0.o:gpsapi.c:(.text+0x1a6): undefined reference to `__imp_curl_easy_setopt'
  C:\Users\Admin\AppData\Local\Temp\ccoDiLJ0.o:gpsapi.c:(.text+0x1c7): undefined reference to `__imp_curl_easy_setopt'
  C:\Users\Admin\AppData\Local\Temp\ccoDiLJ0.o:gpsapi.c:(.text+0x1e8): undefined reference to `__imp_curl_easy_setopt'
  C:\Users\Admin\AppData\Local\Temp\ccoDiLJ0.o:gpsapi.c:(.text+0x209): undefined reference to `__imp_curl_easy_setopt'
  C:\Users\Admin\AppData\Local\Temp\ccoDiLJ0.o:gpsapi.c:(.text+0x219): undefined reference to `__imp_curl_easy_perform'
  C:\Users\Admin\AppData\Local\Temp\ccoDiLJ0.o:gpsapi.c:(.text+0x22c): undefined reference to `__imp_curl_easy_cleanup'
  C:\Users\Admin\AppData\Local\Temp\ccoDiLJ0.o:gpsapi.c:(.text+0x235): undefined reference to `__imp_curl_global_cleanup'
  collect2.exe: error: ld returned 1 exit status
  </code></pre>
  <p>Is this the right way to do it or am I missing something? I am quite new to sending requests in C, so any help is appreciated. Thank you!</p>