O
O
OccamaRazor2016-11-05 08:42:22
Programming
OccamaRazor, 2016-11-05 08:42:22

Referencing an unresolved external symbol?

C language. Why do errors occur? After all, the library in which srand and drand are defined is included
Errors:
reference to an unresolved external symbol _srand48 and the _main
function

/***************************************************************************
#define _XOPEN_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

// constant
#define LIMIT 65536

int main(int argc, char* argv[])
{
    // TODO: comment me
    if (argc != 2 && argc != 3)
    {
        printf("Usage: generate n [s]\n");
        return 1;
    }

    // TODO: comment me
    int n = atoi(argv[1]);

    // TODO: comment me
    if (argc == 3)
    {
        srand48((long int) atoi(argv[2]));
    }
    else
    {
        srand48((long int) time(NULL));
    }

    // TODO: comment me
    for (int i = 0; i < n; i++)
    {
       printf("%i\n", (int) (drand48() * LIMIT));
    }

    // success
    return 0;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Armenian Radio, 2016-11-05
@gbg

Features are deprecated. Use rand().

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question