【问题标题】:make fails to compile, undefined reference to `EVP_DigestUpdatemake 无法编译,未定义对 `EVP_DigestUpdate 的引用
【发布时间】:2013-11-10 01:21:04
【问题描述】:

我正在尝试在我的 ubuntu 13:04 上安装一个开源项目,但 make 过程在名为 updateDB.c 的类中的方法上失败。在编译期间,我有这个错误:

updateDB.o: In function `update_cache_hash':
/usr/local/src/bgpinspect-0.5/src/updateDB.c:142: undefined reference to `EVP_DigestUpdate'
/usr/local/src/bgpinspect-0.5/src/updateDB.c:143: undefined reference to `EVP_DigestFinal_ex'
collect2: error: ld returned 1 exit status
make[1]: *** [BGPdb] Error 1
make[1]: Leaving directory `/usr/local/src/bgpinspect-0.5/src'
make: *** [all] Error 2

这是失败的方法 update_cache_hash

static uint16_t update_cache_hash( char *buff, int size ) {
    unsigned char md_hash[EVP_MAX_MD_SIZE];
    unsigned int md_len;
    uint16_t hash;

    EVP_DigestUpdate(&global_table.ctx, buff, size );
    EVP_DigestFinal_ex(&global_table.ctx, md_hash, &md_len);

    if ( md_len < 2 ) {
        ps_log( PS_LOG_ERROR, "EVP_DigestFinal_ex returned a short hash.\n" );
        return 0;
    }

    hash = ( (uint16_t) md_hash[md_len - 2] << 8 ) | md_hash[md_len - 1];
    hash = UPDATE_CACHE_MASK( hash );

    return hash;
}

这个类的顶部有一个include语句

#include <openssl/evp.h>

我的计算机上安装了 openssl 和 libssl-dev ;我不知道为什么它会给出这个错误,因为我是 c 和静态链接等的新手。 我在这条路径上有 evp.h/usr/include/openssl/evp.h

那么我该如何更改 makefile 或配置以解决此问题?因为似乎 make 看不到这条路径 /usr/include/openssl/evp.h

【问题讨论】:

    标签: c gcc makefile static-linking dynamic-linking


    【解决方案1】:

    undefined reference 错误是链接器错误,因此看起来 gcc 正在查找 /usr/include/openssl/evp.h,但链接器无法找到具有 EVP_DigestUpdateEVP_DigestFinal_ex 函数的库。

    我会检查有问题的 makefile 是否有 -lcrypto 参数,以及 make 是否在您的系统上找到正确的 libcrypto

    【讨论】:

    • 给遇到此问题的任何人的另一个提示,确保 -lssl 出现在 -lcrypto 之前 :) 顺序很重要,go-fig。
    【解决方案2】:

    链接器找不到 libssl 函数。您需要将 libssl 链接到您的项目。

    这篇SO文章有建议:Undefined reference to t1sl_steup_key_block when linking OpenSSL

    例如,在你的 makefile 中,你会添加 -lssl:

    gcc somefile.c -o someprogram -lssl
    

    【讨论】:

    • 感谢您的回复 :) -lssl 已经在 make 文件中,但 -libcrypto 成功了
    猜你喜欢
    • 2013-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-26
    • 1970-01-01
    • 1970-01-01
    • 2015-06-07
    • 1970-01-01
    相关资源
    最近更新 更多