[英]Using #include variables in void functions C++
I am coming back to C++ after a 15 year hiatus and have been struggling to remember how to make variables/functions from the #include available to void functions.在中断了 15 年之后,我又回到了 C++,并且一直在努力记住如何使 #include 中的变量/函数可用于 void 函数。 At present, I'm using a single .cpp but will export the function to a separate .cpp to be called as needed.
目前,我使用的是单个 .cpp,但会将函数导出到单独的 .cpp 以根据需要调用。
I have the following:我有以下几点:
// C++
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <errno.h>
#include <cstring>
// OpenSSL
#include <evp.h>
#include <aes.h>
#include <rand.h>
#include <err.h>
#include <buffer.h>
using namespace std;
typedef struct _cipher_params_t {
unsigned char *key;
unsigned char *iv;
unsigned int encrypt;
const EVP_CIPHER *cipher_type;
}cipher_params_t;
EVP_CIPHER is in the evp.h file but it doesn't seem to be able to find it. EVP_CIPHER 在 evp.h 文件中,但它似乎无法找到它。 My include path seems to be working as I can see/select the modules when I type #include<> and it finds other variables in other includes (aes.h).
我的包含路径似乎正在工作,因为当我输入 #include<> 时我可以看到/选择模块,并且它在其他包含 (aes.h) 中找到其他变量。
Also, in the function below, the items from evp.h cannot not identified such as EVP_CIPHER_CTX *ctx even though it is declared while other items are resolved from other includes such as err.h.此外,在下面的函数中,来自 evp.h 的项目无法识别,例如 EVP_CIPHER_CTX *ctx,即使它被声明而其他项目是从其他包含(例如 err.h)解析的。
void file_encrypt_decrypt(cipher_params_t *params, FILE *ifp, FILE *ofp) {
/* Allow enough space in output buffer for additional block */
int cipher_block_size = EVP_CIPHER_block_size(params->cipher_type);
unsigned char in_buf[BUFSIZE], out_buf[in_buf + cipher_block_size];
int num_bytes_read, out_len;
EVP_CIPHER_CTX *ctx;
:
:
I'm using Visual Studio 2017 Enterprise with openSSL.我正在使用带有 openSSL 的 Visual Studio 2017 Enterprise。 Any suggestions?
有什么建议? A misstated parameter in the link configuration parameters?
链接配置参数中的错误参数?
Any suggestions are greatly appreciated!任何建议都非常感谢! Thanks Rita.
谢谢丽塔。
When setting up a Visual Studio project to use an OpenSSL SDK build, you should do the following (forgive me if the names of the Visual Studio settings aren't quite spot on; I don't have dev-studio running in front of me so I'm doing all this from memory):在设置 Visual Studio 项目以使用 OpenSSL SDK 构建时,您应该执行以下操作(如果 Visual Studio 设置的名称不太准确,请原谅我;我没有在我面前运行 dev-studio所以我是凭记忆做这一切的):
libeay32.lib
to your library file set (should already include kernel32.lib, user32.lib, etc... by inheritance).libeay32.lib
添加到您的库文件集(应该已经包含 kernel32.lib、user32.lib 等...通过继承)。 If you're also using the SSL_xxx apis, you also need ssleay32.lib
on that list.ssleay32.lib
。 With all of that in place, then comes your actual usage of the headers and the contained function decls.有了所有这些,接下来就是您对标头和包含的函数声明的实际使用。 Everywhere you use an OpenSSL API should have that API pulled in by the related header.
您在任何使用 OpenSSL API 的地方都应该通过相关标头引入该 API。 Because OpenSSLDir/include is in the include path, you're halfway there.
因为 OpenSSLDir/include 位于包含路径中,所以您已经完成了一半。 All OpenSSL headers should be included with the following format :
所有 OpenSSL 标头都应包含在以下格式中:
#include <openssl/evp.h>
#include <openssl/sha.h>
#include <openssl/aes.h>
... etc ...
The OpenSSL headers frequently (read: guaranteed to happen) includes other headers in the SDK, which are included with exactly the same nomenclature. OpenSSL 标头经常(阅读:保证发生)包括 SDK 中的其他标头,这些标头包含在完全相同的命名法中。 Therefore, it is critical you set it up to work for you (and thus them) the same way.
因此,将其设置为以相同的方式为您(以及他们)工作是至关重要的。 Following the instructions I've provided, it should work.
按照我提供的说明,它应该可以工作。
I leave the task of ensuring libeay32.dll
and ssleay32.dll
for your build platform are in the proper path or current working directory when it comes to actually running your program, to you.我将确保构建平台的
libeay32.dll
和ssleay32.dll
在实际运行程序时位于正确路径或当前工作目录中的任务留给您。 Ensuring the OpenSSLDir/bin folder is in our path (or startup settings for your Visual Studio debugger) is the easiest way to do it.确保 OpenSSLDir/bin 文件夹在我们的路径(或 Visual Studio 调试器的启动设置)中是最简单的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.