Undefined symbols for x86_64 architecture (clang)

I am trying to use OpenSSL to calculate the sha1 hash from a c program. I am compiling with clang on Mac OS X Yosemite with Intel i7 (so 64 bit).

The corresponding code snippet is something like this:

#include <openssl/evp.h>
...
unsigned char outHash[20]; 
hash("SHA1","abcd", 20, outHash);

The fact is that when using the hash function from openssl/evp.hcompiling with clang, the following error occurs:

Undefined symbols for architecture x86_64:
  "_hash", referenced from:
      _getRandomSHA1 in main-68ccd6.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

So, it looks like OpenSSL was not found by the linker (the hash function is not installed). Any ideas how to fix this?

EDIT:

Turns out I was trying to use a function that doesn't exist ("hash") - sorry for fooling you about this.

However, I still have the same problem: including openssl/evp.h, it does not seem to work.

-, , evp sha1:

unsigned int hash(const char *mode, const char* dataToHash, size_t dataSize, unsigned char* outHashed) {
    unsigned int md_len = -1;
    const EVP_MD *md = EVP_get_digestbyname(mode);
    if(NULL != md) {
        EVP_MD_CTX mdctx;
        EVP_MD_CTX_init(&mdctx);
        EVP_DigestInit_ex(&mdctx, md, NULL);
        EVP_DigestUpdate(&mdctx, dataToHash, dataSize);
        EVP_DigestFinal_ex(&mdctx, outHashed, &md_len);
        EVP_MD_CTX_cleanup(&mdctx);
    }
    return md_len;
}

:

hash("SHA1","abcd", 20, outHash);

, , ( ):

 clang main.c

:

Undefined symbols for architecture x86_64:
  "_EVP_DigestFinal_ex", referenced from:
      _hash in main-935849.o
  "_EVP_DigestInit_ex", referenced from:
      _hash in main-935849.o
  "_EVP_DigestUpdate", referenced from:
      _hash in main-935849.o
  "_EVP_MD_CTX_cleanup", referenced from:
      _hash in main-935849.o
  "_EVP_MD_CTX_init", referenced from:
      _hash in main-935849.o
  "_EVP_get_digestbyname", referenced from:
      _hash in main-935849.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
+4
2
#include <openssl/evp.h>
...
unsigned char outHash[20]; 
hash("SHA1","abcd", 20, outHash);

OpenSSL int hash(...) char* hash(...).

$ cat /usr/include/openssl/evp.h | grep hash 0 . man 3 hash BSD " ".


Undefined symbols for architecture x86_64:
  "_hash", referenced from:
      _getRandomSHA1 in main-68ccd6.o

_getRandomSHA1, SHA, sha.h, evp.h ( DEPRECTAED_IN...):

$ cat /usr/include/openssl/sha.h | grep SHA | grep char
...
unsigned char *SHA(const unsigned char *d, size_t n, unsigned char *md);
...

, , .

EVP Message Digests.


(EDIT): , , ( ):
     clang main.c

. OpenSSL . -lcrypto .


( EDIT, ): openssl at/opt/local/include/openssl....

, , , , OpenSSL. . OpenSSL XCode. Xcode.

. , -lcrypto (-lfoo, , , , ):

 clang main.c -I /opt/local/include /opt/local/lib/libcrypto.a -o my_hash.exe 

- , , .

OX S RPATHs - OpenSSL RPATH, . . | RPATHs OpenSSL OpenSSL RPATH? ..

+4

SDK , Xcode? OpenSSL OS X 10.7 10.11 SDK, - Xcode 7. OpenSSL , .

+1

All Articles