首页 > 解决方案 > ns-3 waf 链接错误(未定义的引用)

问题描述

由于调用./waf. 我已经正确安装了 gcrypt,因为下面的程序在使用g++ test.cpp -o test -lgcrypt.

#include <stdio.h>
#include <gcrypt.h>

int main(void)
{
    char *s = "some text";
    unsigned char *x;
    unsigned i;
    unsigned int l = gcry_md_get_algo_dlen(GCRY_MD_SHA256); /* get digest length (used later to print the result) */

    gcry_md_hd_t h;
    gcry_md_open(&h, GCRY_MD_SHA256, GCRY_MD_FLAG_SECURE); /* initialise the hash context */
    gcry_md_write(h, s, strlen(s)); /* hash some text */
    x = gcry_md_read(h, GCRY_MD_SHA256); /* get the result */

    for (i = 0; i < l; i++)
    {
        printf("%02x", x[i]); /* print the result */
    }
    printf("\n");
    return 0;
}

但是,在 ns-3 中复制此代码会产生与以下链接错误类似类型的多个错误:

/home/xxx/Desktop/ns-allinone-3.28.1/ns-3.28.1/build/../scratch/ns3consensus/AppCons.cc:251: undefined reference to `gcry_md_get_algo_dlen'

此外,ns-3 本身似乎认识到 gcrypt 已安装,因为 的输出./waf configure表明 gcrypt 库已安装Gcrypt library : enabled.

我已按照https://www.nsnam.org/wiki/HOWTO_use_ns-3_with_other_librariesconf.env.append_value("LINKFLAGS", ["-lgcrypt"])的建议添加到顶级 wscript ,但问题仍然存在。是否需要添加任何其他内容来添加 wscript,或者是否还有其他一些我缺少的链接基础知识?

标签: linker-errorsns-3waf

解决方案


这个问题的答案是如何将库包含在waf.

  • 包括由cfg.env.append_value('INCLUDES', ['/usr/local/include']),
  • 库搜索路径由conf.env.append_value('LIBPATH', ["/usr/local/lib"])和添加
  • 在检查/编译/链接时,您使用关键字use=name_of_the_library,因此在这里它会是use='gcrypt'

推荐阅读