2

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.12\src\libsodium\include 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.

wei
  • 937
  • 2
  • 14
  • 34
  • so looks like you haven't linked library properly or haven't linked at all? – codeconscious May 27 '17 at 02:03
  • But I already put sodium.h and sodium folder in my project file and included in my source files – wei May 27 '17 at 02:05
  • 1
    you don't just put it in folder and let compiler understand what it wants to do with these files you gotta link and tell compiler from where you are including headers and stuff. – codeconscious May 27 '17 at 02:13

1 Answers1

3

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.

FKEinternet
  • 1,050
  • 1
  • 11
  • 20