1

I am trying to make a NesC program to use with TOSSIM (TinyOS simulator) including the gmp library Here is a sample of my code

event void Boot.booted()
        {
                //dbg("MAPC", "Booted\n");
                //int g = 2;
                const char * const num = "10387922662657137735272585565990678424704150824246588991894422884684285337052622755228646547137908394766337363629003511269209591656314972254747436173398683";
                int err;

                mpz_t n;
                err = mpz_init_set_str(n, num, 10);

                dbg("MAPC","%d",sizeof(n));

                mpz_clear(n);
        }

The compile runs fine using make micaz sim or env "CFLAGS = -lgmp" make micaz sim When I try to execute it via a python script I get this error:

Traceback (most recent call last):
  File "kdk.py", line 4, in <module>
    from TOSSIM import *
  File "/opt/tinyos-2.1.2/apps/MAP/TOSSIM.py", line 7, in <module>
    import _TOSSIM
ImportError: /opt/tinyos-2.1.2/apps/MAP/_TOSSIMmodule.so: undefined symbol: __gmpz_init_set_str
Crownless
  • 123
  • 1
  • 6

1 Answers1

1

One of the symbols from libgmp cannot be resolved and it looks like it's not compiled with this lib.

You should try using LDFLAGS for -lgmp instead of CFLAGS. However LDFLAGS probably overrides in makefile, so, you'd better update it inside makefile.

pmod
  • 10,450
  • 1
  • 37
  • 50
  • My Makefile contains the following two lines: `COMPONENT=MAPAppC include $(MAKERULES)` So I guess that there is another makefile including everything else. Is there any way I can append my LDFLAGS to those already in use? – Crownless Mar 06 '15 at 21:01
  • @Crownless it depends on the makefile, it can have some special variables for this purpose e.g. EXTERNAL_LIBRARIES, there should be some docs – pmod Mar 06 '15 at 21:04
  • I used LDFLAGS, it didn't override anything, the -lgmp position shifted to were it should be, but I still get this error, thanks a lot for the reply, though. – Crownless Mar 06 '15 at 21:12
  • @Crownless Then, you can try "-L/usr/local/lib -lgmp" (change to path where lib is located) – pmod Mar 06 '15 at 21:32
  • The library is already there. I tried that but has the same result :/ Is there any information I can provide you with? – Crownless Mar 06 '15 at 21:33
  • $ls /usr/local/lib libgmp.a libgmp.la libgmp.so libgmp.so.10 libgmp.so.10.2.0 python2.7 python3.4 site_ruby Τhis is the lib content, but im not sure what you mean about rebuilding the .so module. I've installed this library using the package manager, I don't think I need to rebuild it – Crownless Mar 06 '15 at 21:49
  • @Crownless sorry, that was wrong shot. I think this is related to python inability to load this libgmp, so our LDFLAGS not playing any role. Please include to question output of "ldconfig -p |grep libgmp" – pmod Mar 06 '15 at 22:48