1

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?

user1760
  • 13
  • 3
  • Can you show your whole `wscript`? – user69453 Oct 13 '18 at 10:22
  • https://pastebin.com/swbs3Yxg @user69453 The only changes made to the original wscript are two lines at the start of the configure() function. – user1760 Oct 13 '18 at 11:06
  • Ok there are some things to fix: Includes are added by `cfg.env.append_value('INCLUDES', ['/usr/local/include'])`, and library search paths by `conf.env.append_value('LIBPATH', ["/usr/local/lib"])`, then when checking/compiling/linking you make use of the keyword `use=name_of_the_library`, therefore here it would be `use='gcrypt'`. – user69453 Oct 13 '18 at 12:02
  • @user69453 many thanks, that appears to have done it. If you'd like to rewrite these comments as an answer I will accept it. – user1760 Oct 14 '18 at 03:45

1 Answers1

2

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'.
user69453
  • 1,279
  • 1
  • 17
  • 43