【问题标题】:C++. .so and .h usage. What parameters 'main' want? [closed]C++。 .so 和 .h 的用法。 “主要”需要什么参数? [关闭]
【发布时间】:2013-06-20 17:17:15
【问题描述】:

我已经编译了 .so 库并将其复制到我的新项目中。我还从源文件夹中复制了 .h 文件。

现在我正在尝试使用它。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <iostream>
#include "md5.h"

using namespace std;

int main (int argc, char *argv[]) {
md5_init();
md5_append();
md5_finish();
return 0;
}

在输出我得到一个错误:函数«void md5_init(md5_state_t*)»的参数太少

还有.h文件:

typedef unsigned char md5_byte_t; /* 8-bit byte */
typedef unsigned int md5_word_t; /* 32-bit word */

/* Define the state of the MD5 Algorithm. */
typedef struct md5_state_s {
    md5_word_t count[2];    /* message length in bits, lsw first */
    md5_word_t abcd[4]; /* digest buffer */
    md5_byte_t buf[64]; /* accumulate block */
} md5_state_t;

#ifdef __cplusplus
extern "C"
{
#endif

/* Initialize the algorithm. */

#ifdef WIN32
_declspec(dllexport)
#endif
void md5_init(md5_state_t *pms);

/* Append a string to the message. */
#ifdef WIN32
_declspec(dllexport)
#endif
void md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes);

/* Finish the message and return the digest. */
#ifdef WIN32
_declspec(dllexport)
#endif
void md5_finish(md5_state_t *pms, md5_byte_t digest[16]);

#ifdef __cplusplus
} /* end extern "C" */
#endif

图书馆已经从这个site获得。请参阅 C++ 实现。

我误解了什么?

【问题讨论】:

  • 您是否阅读过文档、标题和示例?

标签: c++ shared-libraries md5 header-files main


【解决方案1】:

您调用的所有 MD5 函数都需要(至少)一个能够存储“消息摘要流”(您要为其生成摘要的字节序列)当前状态的结构。

该结构允许您在多次调用md5_append() 之间存储状态,以及并排运行多个 流,因为给定流的状态完全存储在结构中。

要正确执行此操作,您需要以下内容:

#define HELLO "Hello"
#define SENDR " from Pax"

int main (int argc, char *argv[]) {
    md5_state_t pms;
    md5_byte_t digest[16];

    md5_init (&pms);

    md5_append (&pms, (const md5_byte_t *)HELLO, strlen (HELLO));
    md5_append (&pms, (const md5_byte_t *)SENDR, strlen (SENDR));

    md5_finish (&pms, digest);

    // digest now holds the message digest for the given string.

    return 0;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-13
    • 1970-01-01
    • 2019-11-01
    相关资源
    最近更新 更多