0

When calling __gmpz_set_str() in a NS3, I got this error:

undefined reference to __gmpz_set_str collect2: error: ld returned 1 exit status

I am already including #include <gmpxx.h> and I have also installed libgmp3-dev and libgmp-dev.

Any idea? this is the link to the waf: https://github.com/nsnam/ns-3-dev-git/blob/master/waf and the link to the wscript: https://github.com/nsnam/ns-3-dev-git/blob/master/wscript

# This is the make file content:

#Makefile wrapper for waf

all:
    ./waf

#free free to change this part to suit your requirements

configure:
    ./waf configure --enable-examples --enable-tests

build:
    ./waf build

install:
    ./waf install

clean:
    ./waf clean

distclean:
    ./waf distclean
Noureddine
  • 232
  • 2
  • 10
  • Are you *linking* with gmp? Show your Makefile and linker invocation. – Botje Jul 19 '21 at 08:57
  • 1
    Does this answer your question? [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Botje Jul 19 '21 at 09:00
  • Can we see the waf build script then? You can [edit your post](https://stackoverflow.com/posts/68437605/edit) instead of smushing it into the comments. – Botje Jul 19 '21 at 09:24
  • Can you please edit your post to show how you "call __gmpz_set_str() in a NS3" so we can try to reproduce your issue? Clearly my answer is trying to solve the wrong problem. – Botje Jul 22 '21 at 07:12

2 Answers2

1

The compile flags need to be set at configure time, so the correct incantation is:

LDFLAGS=-lgmp ./waf configure

Now, you can simply run ./waf to build the entire codebase, and the -lgmp flag will be used. If you really want to use make(1), then

LDFLAGS=-lgmp make configure

should also work, but I recommend just using waf directly since it is the actual build system, not make.

Sagar
  • 1,617
  • 9
  • 17
-1

Add the following to the top of your Makefile:

export LINKFLAGS = -lgmp

This will interact with some lines in the wscript to make sure the linker includes libgmp.

Botje
  • 26,269
  • 3
  • 31
  • 41