1

I have example.so, which uses fminf and fmaxf. This code of example does include .

Now the problem is I am writing another sample.cpp code, in whose Makefile I have added LDFLAGS += -lexample to use the APIs under it.

While making this code I get following link error. ../lib/example.so: undefined reference to fminf' ../lib/example.so: undefined reference tofmaxf'

However I tried adding

  1. LDFLAGS += -lstdc++ -lm -lexample.
  2. LDFLAGS += -lexample -lm -lstdc++.

Still both does not work and I get the same error.

Daniel Trugman
  • 8,186
  • 20
  • 41
moizh
  • 55
  • 6
  • Are you getting the error when building `example.so`, or when using the library? If it's when using the library, did you build the library with `-lm` when linking it? How did you build the library? – Some programmer dude Oct 25 '18 at 08:21
  • I am getting error while building sample.cpp. Where I have linked example.so. example.so build fine and .so is created. – moizh Oct 25 '18 at 08:43
  • Might it be [this](https://stackoverflow.com/questions/2624238/c-undefined-references-with-static-library) ? – Neil Gatenby Oct 25 '18 at 08:47
  • @moizh can you add output of `nm -D libexample.so | grep fminf` and `nm -D /path/to/libm.so | grep fminf`? – keltar Oct 25 '18 at 08:48
  • @NeilGatenby I tried this linking order (as mentioned in description) but no luck. – moizh Oct 25 '18 at 09:02
  • @Someprogrammerdude , Yes I have linked library (example.so) with -lm and so it was built successfully. Problem is when using that library(.so) in some other place. – moizh Oct 25 '18 at 09:04
  • @keltar Command: nm -D libexample.so | grep fminf Output: U fminf – moizh Oct 25 '18 at 09:06
  • @moizh and the one in libm? It should be in e.g. `/lib/` or `/lib/x86_64-linux-gnu`. Also could you specify what's full resulting linking line is? – keltar Oct 25 '18 at 09:18
  • You missing a `#include ` anywhere? – Neil Gatenby Oct 25 '18 at 13:34

0 Answers0