首页 > 解决方案 > Visual Studio Intellisense 找到函数,但编译器没有

问题描述

我正在使用 OpenSSL 来尝试让 SHA512 哈希函数工作。当我编写代码时,Visual Studio 的智能感知会找到该函数SHA512以及其中包含的所有参数,但是当我去构建项目时,我收到错误,“函数 main 中引用了未解析的外部符号 SHA512。 " 这是我到目前为止所拥有的,它基于这里的一个小例子。

标准数据文件

// 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>

测试.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;
}

我什至检查并确认 SHA512 也在 stdafx.h 文件中包含的 sha.h 文件中。

标签: c++openssl

解决方案


推荐阅读