-2

I have a C++ application and I have created makefile for it. how,ever I am getting the following error:

/usr/bin/ld: orsProcessor.o: undefined reference to symbol 'atan@@GLIBC_2.2.5'
//lib/x86_64-linux-gnu/libm.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make: *** [ors] Error 1

I am stuck from the past 4 hours. Can someone help me please.?

And my Makefile looks like this:

cc=g++
cflags = -c

all: ors

ors: orsMain.o orsClassifier.o orsObjectData.o orsProcessor.o
    $(CC) orsMain.o orsClassifier.o orsObjectData.o orsProcessor.o -o ors -lstdc++

orsMain.o: orsMain.cpp
      $(CC) -lhighgui.so -limgproc.so -lcore.so $(cflags) orsMain.cpp -o orsMain.o -lstdc++

orsClassifier.o: orsClassifier.cpp
         $(CC) -lhighgui.so -limgproc.so -lcore.so $(cflags) orsClassifier.cpp -o orsClassifier.o -lstdc++ -lm

orsObjectData.o: orsObjectData.cpp
         $(CC) -lhighgui.so -limgproc.so -lcore.so $(cflags) orsObjectData.cpp -o orsObjectData.o -lstdc++ -lm


orsProcessor.o: orsProcessor.cpp
        $(CC) -lhighgui.so -limgproc.so -lcore.so $(cflags)  orsProcessor.cpp -o orsProcessor.o -lstdc++ -lm

clean:
    rm -rf *.o *~ ors

#ORSObjectRecognition.o: ORSObjectRecognition.cpp
#           $(CC) $(cflags) ORSObjectRecognition.cpp
Etan Reisner
  • 77,877
  • 8
  • 106
  • 148
user891558
  • 23
  • 1
  • 3
  • 1
    Notice which function the linker is crying about? `atan`. That should be a red flag that you are not linking against the maths lib (`-lm`). – The Paramagnetic Croissant Feb 04 '15 at 16:40
  • possible duplicate of [undefined reference to "only some math.h" functions](http://stackoverflow.com/questions/6534191/undefined-reference-to-only-some-math-h-functions) – The Paramagnetic Croissant Feb 04 '15 at 16:41
  • Where did `highgui.so`, `imgproc.so`, and `core.so` come from? A different (newer) system? Are you using `atan` in your code? – Etan Reisner Feb 04 '15 at 16:42
  • 1
    this really doesn't have anything to do with c++. – Irrational Person Feb 04 '15 at 16:42
  • it's also very strange that you are trying to produce `.o` object files, but you are actually compiling to full-blown executables and link to libs… that's not how objects files should be created/used… – The Paramagnetic Croissant Feb 04 '15 at 16:43
  • 1
    `orsProcessor.o` is not the name of the target that is built, it's the object file in that the linker finds unresolved dependencies. Building `orsProcessor.o` does not involve the linker (see the `cflags` variable), so `-lm` is useless there. Add it to the recipe for `ors`. – Wintermute Feb 04 '15 at 16:44
  • 1
    Replacing `cc=g++` by `CC=g++` or using `$(CXX)` instead of `$(CC)` to link should work (and allow to remove the `-lstdc++` and `-lm`). – AProgrammer Feb 04 '15 at 16:45

1 Answers1

0

Thanks. I got an answer. I was missing -lm at the end of the first two statements. I added them and the errors got resolved. Thanks, Kushal

user891558
  • 23
  • 1
  • 3