osx和openssl md5

时间:2011-10-26 19:59:08

标签: gcc openssl osx-snow-leopard

我使用gcc版本4.2.1和openssl版本0.9.8r 8 Feb 2011,我尝试了以下代码段

#include<string.h>
#include<stdio.h>
#include<openssl/md5.h>
int main() {
    char test[] = "test";
    unsigned char d[16];

    MD5_CTX c;
    MD5_Init(&c);
    MD5_Update(&c, (char *)test, strlen(test));
    MD5_final(d, &c);
}

编译为gcc -o t <filename.c>会出现以下错误: -

Undefined symbols:
  "_MD5_Update", referenced from:
      _main in ccxSwMKm.o
  "_MD5_Init", referenced from:
      _main in ccxSwMKm.o
  "_MD5_final", referenced from:
      _main in ccxSwMKm.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

有什么明显的东西我做错了吗?

1 个答案:

答案 0 :(得分:3)

尝试将-lcrypto添加到命令行。