NS-3晶片链接错误(未定义参考)

人气:216 发布:2022-10-16 标签: waf ns-3 linker-errors

问题描述

由于调用./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("
");
    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'

此外,由于./waf configure的输出指示gcrypt库已与Gcrypt library : enabled一起安装,ns-3本身似乎识别出gcrypt已安装。

我已经按照https://www.nsnam.org/wiki/HOWTO_use_ns-3_with_other_libraries的建议添加到顶层wscriptconf.env.append_value("LINKFLAGS", ["-lgcrypt"]),但是问题仍然存在。我还需要添加wscript吗?或者我是否缺少其他一些基本的链接?

推荐答案

此问题的答案是如何将库包括在waf中。

Includes由cfg.env.append_value('INCLUDES', ['/usr/local/include']),添加 库搜索路径由conf.env.append_value('LIBPATH', ["/usr/local/lib"])和添加 在检查/编译/链接时,您使用关键字use=name_of_the_库,因此此处的关键字为use='gcrypt'

868