【问题标题】:How can I include <sodium.h> correctly in Visual Studio?如何在 Visual Studio 中正确包含 <sodium.h>?
【发布时间】:2017-10-27 23:25:20
【问题描述】:

我在installation page 阅读了Compilation on Windows 的部分,但我还是很困惑,希望高手能赐教。


我从here下载了LATEST.tar.gz

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

这里是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


【解决方案1】:

您的错误告诉您在 link 时间存在问题 - 所以您的问题不在于包含 sodium.h。有一个库未添加到您的项目中。您不能只是将库复制到您的项目目录中,您需要告诉 Visual Studio 将其链接进去。

【讨论】:

  • 如何让 VS 把它链接进去?
  • 在项目属性对话框中配置属性列表的链接器部分完成
猜你喜欢
  • 2021-01-27
  • 2020-12-28
  • 1970-01-01
  • 2015-11-16
  • 1970-01-01
  • 1970-01-01
  • 2013-12-02
相关资源
最近更新 更多