0

I trying to build brief software. Firstly I create the ./lib/libbrief.so, and secondly I am trying to build main file. The makefile which included in .zip file:

CC=g++

SOURCES=main.cpp
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=main

//#Only enable -msse4.2 on CPUs supporting the POPCNT instruction
CFLAGS = -Wall -DNDEBUG -O3 -march=nocona #-msse4.2 
//#CFLAGS = -Wall -DDEBUG -g -O0 -fno-inline-functions
LDFLAGS = -Wl

//# BRIEF
CFLAGS += -I../brief/include
LDFLAGS += -L../brief/lib -lbrief

//# OpenCV
CFLAGS += `pkg-config opencv --cflags`
LDFLAGS += `pkg-config opencv --libs`

all: $(SOURCES) $(EXECUTABLE)

$(EXECUTABLE): $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) -o $@

.cpp.o:
$(CC) -g -c $(CFLAGS) $< -o $@

 clean:
rm -f $(OBJECTS) $(EXECUTABLE) matches.png

However I am getting errors, related with opencv. The errors found:

g++ -Wl -L../brief/lib -lbrief `pkg-config opencv --libs` main.o -o main
main.o: In function `~BRIEF':
Desktop/asdf/brief_v1.0/test_app/../brief/include/brief/BRIEF.hpp:203:     
undefined reference to `cvReleaseImage'
Desktop/asdf/brief_v1.0/test_app/../brief/include/brief/BRIEF.hpp:204:
undefined reference to `cvReleaseImage'
main.o: In function `BRIEF':
Desktop/asdf/brief_v1.0/test_app/../brief/include/brief/BRIEF.hpp:156:   
undefined reference to `cvCreateImage'
Desktop/asdf/brief_v1.0/test_app/../brief/include/brief/BRIEF.hpp:157:
undefined reference to `cvCreateImage'
main.o: In function `TestSampler<signed char>::sampleGaussian(signed char*, int, int)'
main.o: In function `BRIEF':
Desktop/asdf/brief_v1.0/test_app/../brief/include/brief/BRIEF.hpp:156: 
undefined reference to `cvCreateImage'
Desktop/asdf/brief_v1.0/test_app/../brief/include/brief/BRIEF.hpp:157: 
undefined reference to `cvCreateImage'
main.o: In function `TestSampler<signed char>::sampleGaussian(signed char*, int, int)':
main.o: In function `BRIEF::writeTests(std::basic_string<char, std::char_traits<char>, 
std::allocator<char> > const&) const':
Desktop/asdf/brief_v1.0/test_app/../brief/include/brief/BRIEF.hpp:511: 
undefined reference to `utils::stdoutError(std::basic_string<char, 
std::char_traits<char>, 
std::allocator<char> >, char const*, int, char const*)'
main.o: In function `BRIEF::readTests(std::basic_string<char, std::char_traits<char>,  
std::allocator<char> > const&)':
Desktop/asdf/brief_v1.0/test_app/../brief/include/brief/BRIEF.hpp:524: 
undefined reference to `utils::stdoutError(std::basic_string<char,
std::char_traits<char>, 
std::allocator<char> >, char const*, int, char const*)'
main.o: In function `detectSURF':
Desktop/asdf/brief_v1.0/test_app/main.cpp:92: undefined reference to  
`cvCreateMemStorage'
Desktop/asdf/brief_v1.0/test_app/main.cpp:101: undefined reference to
`cvExtractSURF'
Desktop/asdf/brief_v1.0/test_app/main.cpp:106: undefined reference to    
`cvGetSeqElem'
main.o: In function `timeDescription(int)':
Desktop/asdf/brief_v1.0/test_app/main.cpp:201: undefined reference to
`cvLoadImage'
Desktop/asdf/brief_v1.0/test_app/main.cpp:214: undefined reference to 
`cvReleaseImage'
main.o: In function `~BRIEF':

What have to do to build proper the main.cpp?

MadScientist
  • 92,819
  • 9
  • 109
  • 136
snake plissken
  • 2,649
  • 10
  • 43
  • 64
  • Can you please elaborate a bit on how you solved the problem because I get the exact same error but I don't really understood the solution. Thanks – Vasilis Apr 20 '14 at 05:24

1 Answers1

0

You must list all the object files on the link like before the libraries that they use.

See, for example, Why does the order in which libraries are linked sometimes cause errors in GCC?

Community
  • 1
  • 1
MadScientist
  • 92,819
  • 9
  • 109
  • 136
  • Can you please elaborate on the solution because I have the exact same problem with snake plissken but didn't figure out how to solve it from your answer. Thanks. – Vasilis Apr 20 '14 at 05:25
  • I'm not sure what else to say: your linker command line will have objects (files that end in `.o`) and libraries (added using the `-l` flag: things like `-lm` etc.) On the linker command line, all the objects should be listed before any of the libraries. Also, the order in which the libraries themselves are listed can make a difference: for any library X that uses a feature of library Y, the `-lX` flag should come _before_ the `-lY` flag. If that doesn't help please create a new question and provide details of your link line and the errors you see. – MadScientist Apr 20 '14 at 16:46
  • Just to be clear, the order that object files are listed in relationship to each other is completely irrelevant. – MadScientist Apr 20 '14 at 16:48