2

我在安装页面阅读了Compilation on Windows的部分,但我仍然很困惑,希望高手能赐教。


LATEST.tar.gz这里下载。

之后,我复制sodium.hsodium文件夹libsodium-1.0.12\src\libsodium\include到我的项目中。

这是代码

#include <stdio.h>
#include "sodium.h"
#pragma warning (disable:4996)

void main()
{
    char myString[32];
    uint32_t myInt;

    /* myString will be an array of 32 random bytes, not null-terminated */
    randombytes_buf(myString, 32);

    /* myInt will be a random number between 0 and 9 */
    myInt = randombytes_uniform(10);

    printf("%d", myInt);

    system("pause");
}

编译时出现这些错误:

错误 LNK1120 2 未解决的外部

函数 _main 中引用的错误 LNK2019 未解析的外部符号 __imp__randombytes_buf

函数 _main 中引用的错误 LNK2019 未解析的外部符号 __imp__randombytes_uniform

我没有收到像“无法打开 sodium.h”这样的错误。

我该如何解决这个问题?

任何帮助表示赞赏。

4

1 回答 1

2

Your errors are telling you there's a problem at link time - so your issue isn't with including sodium.h. There's a library that's not being added to your project. You can't just copy the library to your project directory, you need to tell Visual Studio to link it in.

于 2017-05-27T02:04:05.940 回答