Unable to use GMP with Omnet++

后端 未结 2 1357
耶瑟儿~
耶瑟儿~ 2021-01-29 10:34

I have installed GMP on ubuntu. I download GMP-6.1.2 from \"https://gmplib.org\".Then I extracted it in Home folder and installed like:

1. cd gmp-6.1.2
2../confi         


        
相关标签:
2条回答
  • 2021-01-29 10:58

    Assuming that you have installed libgmp using sudo apt-get install libgmp3-dev in your OMNeT++ project you have to do:

    1. In header file (*.h) of simple module where you want to use gmp add:

      #include <gmp.h>
      
    2. Go to Project Properties, choose OMNeT++ | Makemake | select src | Options | Custom | Makefrag and write:

      EXTRA_OBJS=-lgmp
      

    To check you can add the following code somewhere in your source file, for example in initialize():

        mpz_t a, b, c;
        mpz_init_set_str(a, "123", 10);
        mpz_init_set_str(b, "458", 10);
        mpz_init(c);
        mpz_add(c, a, b);
    
        char * ctxt = mpz_get_str(NULL, 10, c);
        EV << "c=" << ctxt << std::endl;  // print the result
        mpz_clear(a);
        mpz_clear(b);
        mpz_clear(c);
    
    0 讨论(0)
  • 2021-01-29 11:17

    I think I can do that.

    I have installed gmp in ubuntu. Then I added "gmp.h" and "gmpXX.h" to my project.

    After that,I went to project properties | omnet++ | select SRC | Options | link | Additional libraries to link with:(-l option) and I inserted these two Option: gmpxx , gmp .

    Also,I added "/usr/local/include" in "paths and symbols(in project properties) | includes " and "/usr/local/lib" in " paths and symbols | library paths ".

    After that,I added "/usr/include" in "paths and symbols(in project properties) | includes " and "/usr/lib/i386-linux-gnu" in " paths and symbols | library paths ".

    And I built my project without any error.

    At last,I run dear Jurzy D's example without any error.

    I did not change any thing else.

    0 讨论(0)
提交回复
热议问题