How can I include <sodium.h> correctly in Visual Studio?

I read section Compilation on Windows in installation page but I still very confused, I hope some experts can enlighten me.


I downloaded LATEST.tar.gz from here.

After that, I copied sodium.h and sodium folder in libsodium-1.0.12srclibsodiuminclude to my project.

Here is 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");
}

And I get these errors when compiling:

Error LNK1120 2 unresolved externals

Error LNK2019 unresolved external symbol __imp__randombytes_buf referenced in function _main

Error LNK2019 unresolved external symbol __imp__randombytes_uniform referenced in function _main

I did not get error like "cannot open sodium.h".

How can I solve this?

Any help is appreciated.


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.

链接地址: http://www.djcxy.com/p/65876.html

上一篇: MySQL更改外键的类型

下一篇: 如何在Visual Studio中正确包含<sodium.h>?