lundi 18 juin 2018

Linker errors while including a static library(which includes openssl internally) to a Dll

I am working in Windows environment. I am implementing a Dll which is used by an console application. My implementation of a dll(say D) includes static library(say L). Also static library L includes Openssl.lib. I am seeing linker errors while building DLL(D) which are pointing to Openssl.lib.

Inclusion of Openssl Header files in xxxx.cpp file is as:

#include <openssl/evp.h>
#include <openssl/hmac.h>
#include <openssl/aes.h>
int openssl_hmac_vector(const EVP_MD *type, const u8 *key,
               size_t key_len, size_t num_elem,
               const u8 *addr[], const size_t *len, u8 *mac,
               unsigned int mdlen)
{
    HMAC_CTX ctx;
    size_t i;
    int res;

    HMAC_CTX_init(&ctx);
 #if OPENSSL_VERSION_NUMBER < 0x00909000
    HMAC_Init_ex(&ctx, key, key_len, type, NULL);
 #else /* openssl < 0.9.9 */
    if (HMAC_Init_ex(&ctx, key, key_len, type, NULL) != 1)
       return -1;
  #endif /* openssl < 0.9.9 */

   for (i = 0; i < num_elem; i++)
       HMAC_Update(&ctx, addr[i], len[i]);

  #if OPENSSL_VERSION_NUMBER < 0x00909000
      HMAC_Final(&ctx, mac, &mdlen);
     res = 1;
  #else /* openssl < 0.9.9 */
     res = HMAC_Final(&ctx, mac, &mdlen);
  #endif /* openssl < 0.9.9 */
     HMAC_CTX_cleanup(&ctx);

    return res == 1 ? 0 : -1;
  }

Observations: 1. Did not see any build errors while building library(L) by including Openssl.lib 2. If I change Library L output to Dynamic from static(marked with red in below image) , I am seeing linker errors in Openssl.lib

Sources file of Library L:

[![enter image description here][1]][1]

Linker errors: Error 12 error LNK2001: unresolved external symbol _HMAC_CTX_cleanup@4
Error 13 error LNK2001: unresolved external symbol _HMAC_Final@12
Error 15 error LNK2001: unresolved external symbol _HMAC_Init_ex@20
Error 16 error LNK2001: unresolved external symbol _HMAC_CTX_init@4

Please suggest me the changes in my code to resolve the linker errors.

Thanks

Aucun commentaire:

Enregistrer un commentaire