-2

So I was following this tutorial: https://nickfarrow.com/Cryptography-in-Bitcoin-with-C/ I installed libsecp256k1 from https://www.howtoinstall.me/ubuntu/18-04/libsecp256k1-dev/ but while compiling my program:

#include <secp256k1.h>
#include <stdio.h>
static secp256k1_context *ctx = NULL;

int main()
{
    ctx = secp256k1_context_create(
        SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY);
    /* Declare the private variable as a 32 byte unsigned char */
    unsigned char seckey[32];

    /* Load private key (seckey) from random bytes */
    FILE *frand = fopen("/dev/urandom", "r");

    /* Read 32 bytes from frand */
    fread(seckey, 32, 1, frand);

    /* Close the file */
    fclose(frand);

    /* Loop through and print each byte of the private key, */
    printf("Private Key: ");
    for (int i = 0; i < 32; i++)
    {
        printf("%02X", seckey[i]);
    }
    printf("\n");
}

i get:

josh@pc:~/Code$ gcc prvkey.c -o exec
/tmp/cc5OVPMJ.o: In function `main':
prvkey.c:(.text+0x1d): undefined reference to `secp256k1_context_create'
collect2: error: ld returned 1 exit status

Thanks in advance!

1 Answers1

2

Try:

gcc prvkey.c -o exec -lcrypto -lsecp256k1

gcc -l links with a library file.

Let me know if that works or any questions let me know.

Antoine
  • 1,393
  • 4
  • 20
  • 26
  • You may not need the crypto lib but to get https://nickfarrow.com/assets/btc_gen.c to compile you would need crypto lib and the secp256k1 library. – Music Anarchy Dec 31 '21 at 12:53