ns-3 waf 链接错误(未定义的引用)

ns-3 waf linking error (undefined references)

由于调用 ./waf 后出现链接错误,我目前在尝试使用 ns-3 中的 gcrypt 库代码时遇到问题。我已经正确安装了 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_libraries 的建议将 wscript conf.env.append_value("LINKFLAGS", ["-lgcrypt"]) 添加到顶层,但问题仍然存在。我还需要添加 wscript 吗?还是缺少其他一些链接基础知识?

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

  • 包含由 cfg.env.append_value('INCLUDES', ['/usr/local/include'])
  • 添加
  • 图书馆搜索路径由conf.env.append_value('LIBPATH', ["/usr/local/lib"])
  • 添加
  • 当checking/compiling/linking你使用关键字use=name_of_the_library时,因此这里是use='gcrypt'.