-2

I have three files, rsa.c, prf.c, and rsa-test.c.

I use gcc -c rsa.c, gcc -c prf.c, gcc -c rsa-test.c to get the .o files.

EDIT: I included rsa.c and prf.c in rsa-test.c.

Then I compile the .o files using gcc -o test rsa.o prf.o rsa-test.o.

I get the following error when I compile the. o files of three files.

Undefined symbols for architecture x86_64:
  "_EVP_sha512", referenced from:
      randBytes(unsigned char*, unsigned long) in prf.o
  "_HMAC", referenced from:
      randBytes(unsigned char*, unsigned long) in prf.o
  "_SHA512", referenced from:
      setSeed(unsigned char*, unsigned long) in prf.o
  "___gmpz_add_ui", referenced from:
      randBytes(unsigned char*, unsigned long) in prf.o
  "___gmpz_clear", referenced from:
      rsa_shredKey(_RSA_KEY*) in rsa.o
  "___gmpz_export", referenced from:
      zToFile(__sFILE*, __mpz_struct*) in rsa.o
  "___gmpz_import", referenced from:
      zFromFile(__sFILE*, __mpz_struct*) in rsa.o
  "___gmpz_init", referenced from:
      rsa_initKey(_RSA_KEY*) in rsa.o
      setSeed(unsigned char*, unsigned long) in prf.o
  "___gmpz_limbs_read", referenced from:
      randBytes(unsigned char*, unsigned long) in prf.o
  "___gmpz_limbs_write", referenced from:
      rsa_shredKey(_RSA_KEY*) in rsa.o
  "___gmpz_set_ui", referenced from:
      rsa_initKey(_RSA_KEY*) in rsa.o
      setSeed(unsigned char*, unsigned long) in prf.o
  "___gmpz_size", referenced from:
      zToFile(__sFILE*, __mpz_struct*) in rsa.o
      rsa_numBytesN(_RSA_KEY*) in rsa.o
      rsa_shredKey(_RSA_KEY*) in rsa.o
      randBytes(unsigned char*, unsigned long) in prf.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I'm not sure what is causing this error. The linker seems like the problem, because I'm using functions from rsa.c and prf.c in rsa-test.c and that's what's causing this problem.

Please let me know if you would like to test my files, I will post them up.

Pete
  • 754
  • 2
  • 13
  • 27
  • Maybe you have to link some libraries using `-l` option. – MikeCAT Sep 22 '15 at 02:46
  • 1
    windows from the extra leading underscore character in the symbols ? `gcc -o test rsa.o prf.o rsa-test.o -lgmp -lcrypto` where gmp.dll is GMP https://en.wikipedia.org/wiki/GNU_Multiple_Precision_Arithmetic_Library and crypto.dll is https://en.wikipedia.org/wiki/OpenSSL – Darryl Miles Sep 22 '15 at 02:47

2 Answers2

3

You need to link to the libraries you're using by adding link flags to the gcc -o command.

It looks like you're using GMP, so that flag should be -lgmp.

If the other library involved is OpenSSL, try -lcrypto or see here if you built it from source.

gcc -o test_linked.exe rsa.o prf.o rsa-test.o -lgmp -lcrypto
Community
  • 1
  • 1
Iskar Jarak
  • 5,136
  • 4
  • 38
  • 60
1

While linking you should include libraries or shared libraries along with optionla library path with -L option an example of such

gcc -o binary *.o -L /path/to/libraries -llibrary

where -llibrary will look something like this

liblibrary.so or liblibrary.so* 
asio_guy
  • 3,667
  • 2
  • 19
  • 35