user1760
user1760

Reputation: 13

ns-3 waf linking error (undefined references)

I am currently experience problems attempting to use code from the gcrypt library in ns-3 due to a linking error after invoking ./waf. I have installed gcrypt correctly as the below program works fine when compiled with 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;
}

However, replicating this code in ns-3 produces multiple errors of a similar type to the following error on linking:

/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'

Additionally, ns-3 itself seems to recognise that gcrypt is installed as the output of ./waf configure indicates that the gcrypt library is installed with Gcrypt library : enabled.

I have added to the top level wscript conf.env.append_value("LINKFLAGS", ["-lgcrypt"]) as suggested by https://www.nsnam.org/wiki/HOWTO_use_ns-3_with_other_libraries , the issue remains however. Is there anything additional I need to add the wscript or is there some other fundamentals of linking I am missing?

Upvotes: 1

Views: 1956

Answers (1)

user69453
user69453

Reputation: 1405

The answer to this problem is how libraries are included in waf.

  • Includes are added by cfg.env.append_value('INCLUDES', ['/usr/local/include']),
  • library search paths are added by conf.env.append_value('LIBPATH', ["/usr/local/lib"]) and
  • when checking/compiling/linking you make use of the keyword use=name_of_the_library, therefore here here it would be use='gcrypt'.

Upvotes: 2

Related Questions