0

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:

Sources file of Library L

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

Joseph D.
  • 11,804
  • 3
  • 34
  • 67
  • The errors show mangled names of opensssl functions, I am unsure why when openssl headers already use extern "C" block if __cplusplus is defined – Pras Jun 18 '18 at 15:59
  • For Windows, those symbols live in the OpenSSL library called `libeay32`, which you do not seem to have in your list. – Reinier Torenbeek Jun 19 '18 at 14:08
  • Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – 1201ProgramAlarm Jun 19 '18 at 21:10

0 Answers0