Reference not set for "crypt" error in linkage

Asked

Viewed 122 times

0

I am used the "crypt" function in that following code:

#define _XOPEN_SOURCE
#include <unistd.h>
#include <stdio.h>

int main(void)
{
    char *key = "rdf";
    char *salt = "50";
    char *hash = crypt(key, salt);

    printf("%s\n", hash);
}

and I’m getting this bug at compile time :

inserir a descrição da imagem aqui

  • 1

    This error is not of compilation, it is of linkage (yes, it seems pedanticism, but it is good to know the difference, has several answers here about linkediting and the final assembly process of the executable). Some -lmylib is missing apparently. I’m not used to working with unistd.h

1 answer

0

I’ve done a lot of research and I think I’ve found a solution to your problem.

According to this website when you use a compiler ISO C, it is necessary to declare the prototype of the function. I believe that this is your case.

So, according to the same, you’d have to do it like this:

#define _XOPEN_SOURCE
#include <unistd.h>
#include <stdio.h>

//Declaração do protótipo da função
char *crypt(const char *, const char *);

int main(void)
{
    char *key = "rdf";
    char *salt = "50";
    char *hash = crypt(key, salt);

    printf("%s\n", hash);
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.