1

I'm using an Intel Mac running Catalina 10.15.1

I'm trying to use libsodium using gcc Apple clang version 11.0.0 (clang-1100.0.33.12)

I have both tried to install libsodium via home-brew and manually compile (which was successful), however, when trying to use libsodium I get this error:

Undefined symbols for architecture x86_64:
  "_crypto_generichash", referenced from:
      _main in sodium-ae2fd0.o
  "_sodium_init", referenced from:
      _main in sodium-ae2fd0.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

This is the basic code, using libsodium: stable 1.0.18 (bottled), HEAD

  1 #include <sodium.h>
  2
  3 int main(void)
  4 {
  5
  6     sodium_init();
  7
  8     #define MESSAGE ((const unsigned char *) "Arbitrary data to hash")
  9     #define MESSAGE_LEN 22
 10
 11     unsigned char hash[crypto_generichash_BYTES];
 12
 13     crypto_generichash(hash, sizeof hash,
 14                        MESSAGE, MESSAGE_LEN,
 15                        NULL, 0);
 16
 17     return 0;
 18 }

Any ideas?

Woodstock
  • 22,184
  • 15
  • 80
  • 118

1 Answers1

1

The issue is probably not in the libsodium installation, but in the way your example application is compiled.

In order to link a library (besides the C library which is implicitly linked) when compiling a C program, you need to add the -l<library name> flag to the compilation command line:

cc -Wall -W -o example example.c -lsodium
Frank Denis
  • 1,475
  • 9
  • 12
  • Thank you! That's worked perfectly. Spend most of my time in Swift so sometimes C gets the better of me. – Woodstock Nov 30 '19 at 10:57