1

I am working with OpenSSL to try and get the SHA512 Hash function to work. When I am writing the code, Visual Studio's intellisense finds the function SHA512as well as all of the parameters that are included with it, but when I go to build the project, I get the error, "unresolved external symbol SHA512 referenced in function main." Here is what I have so far, it's based on a small example here.

stdafx.h

// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//

#pragma once

#include "targetver.h"

#include <stdio.h>
#include <tchar.h>
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS      // some CString constructors will be explicit
#define _AFX_NO_MFC_CONTROLS_IN_DIALOGS         // remove support for MFC controls in dialogs

#ifndef VC_EXTRALEAN
#define VC_EXTRALEAN            // Exclude rarely-used stuff from Windows headers
#endif

#include <afx.h>
#include <afxwin.h>         // MFC core and standard components
#include <afxext.h>         // MFC extensions
#ifndef _AFX_NO_OLE_SUPPORT
#include <afxdtctl.h>           // MFC support for Internet Explorer 4 Common Controls
#endif
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h>                     // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT

#include <iostream>



// TODO: reference additional headers your program requires here
#include <openssl/sha.h>

test.cpp

#include "stdafx.h"
#include <stdio.h>
#include <string.h>


int main() {
    unsigned char digest[SHA512_DIGEST_LENGTH];
    char string[] = "hello world";

    SHA512((unsigned char*)&string, strlen(string), (unsigned char*)&digest);

    char mdString[SHA512_DIGEST_LENGTH * 2 + 1];

    for (int i = 0; i < SHA512_DIGEST_LENGTH; i++)
        sprintf(&mdString[i * 2], "%02x", (unsigned int)digest[i]);

    printf("SHA512 digest: %s\n", mdString);

    return 0;
}

I have even checked and confirmed that SHA512 is in the sha.h file that is included in the stdafx.h file as well.

Eric Brown
  • 1,312
  • 3
  • 15
  • 30
  • The compiler is right. Are you linking with the library? – MivVG Jul 17 '18 at 21:07
  • intellisense only needs the function declaration - the linker needs the definition –  Jul 17 '18 at 21:08
  • @MivVG Shoot, that's what happened, I switched from x86 to x64 and I forgot to add the library to the linker for the x64 version. Thanks. – Eric Brown Jul 17 '18 at 21:12

0 Answers0