【发布时间】:2017-10-27 23:25:20
【问题描述】:
我在installation page 阅读了Compilation on Windows 的部分,但我还是很困惑,希望高手能赐教。
我从here下载了LATEST.tar.gz。
之后,我将libsodium-1.0.12\src\libsodium\include中的sodium.h和sodium文件夹复制到我的项目中。
这里是the code:
#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");
}
编译时出现这些错误:
Error LNK1120 2 unresolved externals
错误 LNK2019 未解析的外部符号 __imp__randombytes_buf 在函数_main中引用
错误 LNK2019 未解析的外部符号 __imp__randombytes_uniform 在函数_main中引用
我没有收到类似“无法打开 sodium.h”的错误。
我该如何解决这个问题?
感谢任何帮助。
【问题讨论】:
-
看来您没有正确链接库或根本没有链接?
-
但是我已经把sodium.h和sodium文件夹放在我的项目文件中并包含在我的源文件中
-
你不只是把它放在文件夹中,让编译器了解它想对这些文件做什么,你必须链接并告诉编译器你从哪里包含标题和东西。
标签: c header-files visual-studio-2017 unresolved-external sodium