title: Errors during linking a static cURL using CMake
body: <p>I'm trying to build example program which uses cURL library. Unfortunately I've got a lot of errors during linking. </p>
  
  <p>System: Linux-x86_64, GCC version 7.2.2 </p>
  
  <p>1) Because SSL support is needed, firstable I built OpenSSL library. I downloaded openssl-1.1.1-pre5.tar.gz, unpacked and configured it for static build:</p>
  
  <pre><code>$ ./Configure --prefix="${HOME}/Source/openssl-1.1.1-pre5" no-shared linux-x86_64
  </code></pre>
  
  <p>then</p>
  
  <pre><code>$ make VERBOSE=1
  $ make install
  </code></pre>
  
  <p>2) Next, I prepared ZLib library: downloaded zlib-1.2.11.tar.gz, unpacked and configured it for static build: </p>
  
  <pre><code>$ ./configure --prefix="${HOME}/Source/zlib-1.2.11" --static
  </code></pre>
  
  <p>then</p>
  
  <pre><code>$ make VERBOSE=1
  $ make install
  </code></pre>
  
  <p>3) Then I built cURL, also as static library:</p>
  
  <pre><code>$ ./configure --prefix="${HOME}/Source/curl-7.59.0" --with-ssl="${HOME}/Source/openssl-1.1.1-pre5" --with-zlib="${HOME}/Source/zlib-1.2.11" --enable-static --disable-shared
  </code></pre>
  
  <p>...
    summary of configuring:</p>
  
  <pre><code>  curl version:     7.59.0
    Host setup:       x86_64-pc-linux-gnu
    Install prefix:   /home/sergei/Source/curl-7.59.0
    Compiler:         gcc
    SSL support:      enabled (OpenSSL)
    SSH support:      no      (--with-libssh2)
    zlib support:     enabled
    brotli support:   no      (--with-brotli)
    GSS-API support:  no      (--with-gssapi)
    TLS-SRP support:  enabled
    resolver:         POSIX threaded
    IPv6 support:     enabled
    Unix sockets support: enabled
    IDN support:      no      (--with-{libidn2,winidn})
    Build libcurl:    Shared=no, Static=yes
    Built-in manual:  enabled
    --libcurl option: enabled (--disable-libcurl-option)
    Verbose errors:   enabled (--disable-verbose)
    SSPI support:     no      (--enable-sspi)
    ca cert bundle:   /etc/ssl/certs/ca-certificates.crt
    ca cert path:     no
    ca fallback:      no
    LDAP support:     no      (--enable-ldap / --with-ldap-lib / --with-lber-lib)
    LDAPS support:    no      (--enable-ldaps)
    RTSP support:     enabled
    RTMP support:     no      (--with-librtmp)
    metalink support: no      (--with-libmetalink)
    PSL support:      no      (libpsl not found)
    HTTP2 support:    disabled (--with-nghttp2)
    Protocols:        DICT FILE FTP FTPS GOPHER HTTP HTTPS IMAP IMAPS POP3 POP3S RTSP SMB SMBS SMTP SMTPS TELNET TFTP
  </code></pre>
  
  <p>then</p>
  
  <pre><code>$ make VERBOSE=1
  $ make install
  </code></pre>
  
  <p>and after build finished, I've got cURL dir structure in ${HOME}/Source/curl-7.59.0:</p>
  
  <pre><code>/bin
  /include
  /lib    &lt;-- here are libcurl.a and libcurl.la 
  /share
  </code></pre>
  
  <p>4) Next I prepared example, which I had got from simple.c (cURL example from /docs/examples): </p>
  
  <pre class="lang-c prettyprint-override"><code>#include &lt;iostream&gt;
  #include &lt;stdio.h&gt;
  
  #define CURL_STATICLIB
  #include &lt;curl/curl.h&gt;    
  
  int main(int argc, char** argv) 
  {
      CURL *curl;
      CURLcode res;
  
      curl = curl_easy_init();
  
      if(curl) 
      {
          curl_easy_setopt(curl, CURLOPT_URL, "http://rambler.ru");
  
          /* example.com is redirected, so we tell libcurl to follow redirection */
          curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
  
          /* Perform the request, res will get the return code */
          res = curl_easy_perform(curl);
  
          /* Check for errors */
          if(res != CURLE_OK)
            fprintf(stderr, "curl_easy_perform() failed: %s\n",
                    curl_easy_strerror(res));
  
          /* always cleanup */
          curl_easy_cleanup(curl);
      }
  
      return 0; 
  }
  </code></pre>
  
  <p>wrote CMakeLists.txt: 
  </p>
  
  <pre><code>cmake_minimum_required(VERSION 2.8) 
  
  project(curl_example) 
  
  set(SOURCE_EXE main.cpp)
  
  add_library(curl_library STATIC IMPORTED) 
  
  set_target_properties(curl_library PROPERTIES IMPORTED_LOCATION 
                        "/home/sergei/Source/curl-7.59.0/lib/libcurl.a")
  
  include_directories("/home/sergei/Source/curl-7.59.0/include")
  
  
  add_executable(main ${SOURCE_EXE})
  
  target_link_libraries(main curl_library) 
  </code></pre>
  
  <p>and when I tried to build, I've got a lot of errors (after line "[100%] Linking CXX executable main"), like this: </p>
  
  <pre><code>/home/sergei/Source/curl-7.59.0/lib/libcurl.a(libcurl_la-version.o): In function `curl_version.part.0':
  version.c:(.text+0x68): undefined reference to `zlibVersion'
  /home/sergei/Source/curl-7.59.0/lib/libcurl.a(libcurl_la-version.o): In function `curl_version_info.part.1':
  version.c:(.text+0xde): undefined reference to `zlibVersion'
  /home/sergei/Source/curl-7.59.0/lib/libcurl.a(libcurl_la-content_encoding.o): In function `gzip_init_writer':
  content_encoding.c:(.text+0x230): undefined reference to `zlibVersion'
  content_encoding.c:(.text+0x266): undefined reference to `inflateInit2_'
  content_encoding.c:(.text+0x289): undefined reference to `inflateInit2_'
  /home/sergei/Source/curl-7.59.0/lib/libcurl.a(libcurl_la-content_encoding.o): In function `exit_zlib':
  content_encoding.c:(.text+0x31c): undefined reference to `inflateEnd'
  /home/sergei/Source/curl-7.59.0/lib/libcurl.a(libcurl_la-content_encoding.o): In function `inflate_stream':
  content_encoding.c:(.text+0x435): undefined reference to `inflate'
  content_encoding.c:(.text+0x4eb): undefined reference to `inflateEnd'
  content_encoding.c:(.text+0x504): undefined reference to `inflateInit2_'
  </code></pre>
  
  <p>and like this: </p>
  
  <pre><code>openssl.c:(.text+0x4ae): undefined reference to `SSL_get_error'
  openssl.c:(.text+0x4c3): undefined reference to `ERR_get_error'
  openssl.c:(.text+0x553): undefined reference to `ERR_error_string_n'
  /home/sergei/Source/curl-7.59.0/lib/libcurl.a(libcurl_la-openssl.o): In function `ssl_ui_writer':
  openssl.c:(.text+0x8e0): undefined reference to `UI_get_string_type'
  openssl.c:(.text+0x8f0): undefined reference to `UI_get0_user_data'
  openssl.c:(.text+0x8fd): undefined reference to `UI_get_input_flags'
  openssl.c:(.text+0x906): undefined reference to `UI_OpenSSL'
  openssl.c:(.text+0x90e): undefined reference to `UI_method_get_writer'
  </code></pre>
  
  <p>Could you please help me: what do I do wrong??</p>
  
  <p>P.S.: adding line "add_definitions(-DCURL_STATICLIB)" to the CMakeLists.txt has no effect.</p>
  
  <p>Thanks.</p>