I recently inherited some OpenCV code. I installed openCV on my mac, built in in XCode, and then compiled and successfully ran my first openCV "hello world"-ish program.
Now I'm trying to run the code I was given, but I get errors that lead me to believe it's an issue with the original code being run on a 32-bit Windows system and mine being on a 64-bit Mac.
When I run the Makefile by entering "make"
CC = g++
CFLAGS =
LDFLAGS = -I/usr/local/include/opencv -lm -lopencv_core -lopencv_highgui -lopencv_video
ALL = vision
all: $(ALL)
vision: vision.o
$(CC) $(LDFLAGS) -o $@ $^
vision.o: vision.cpp
$(CC) $(LDFLAGS) -c $<
.PHONY: clean
clean:
rm -rf *.o core* $(ALL)
I get the following output…
g++ -I/usr/local/include/opencv -lm -lopencv_core -lopencv_highgui -lopencv_video -o vision vision.o
Undefined symbols for architecture x86_64:
"cv::equalizeHist(cv::Mat const&, cv::Mat&)", referenced from:
_main in vision.o
"cv::threshold(cv::Mat const&, cv::Mat&, double, double, int)", referenced from:
_main in vision.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [vision] Error 1
I'm confused; does this mean my install of OpenCV is wrong, the code (those methods specifically) needs to be changed, or something else entirely?
Note: When I comment out the problem methods from the vision.cpp code, everything compiles just fine.
Add opencv_imgproc
to your LDFLAGS:
LDFLAGS = -I/usr/local/include/opencv -lm -lopencv_core -lopencv_highgui -lopencv_video -lopencv_imgproc
Here is a working example:
CXX = g++
SOURCES = aaa.cpp bbb.cpp
OBJS = $(SOURCES:.cpp=.o)
CXXFLAGS = -I. -I/opt/local/include \
-std=c++11 -stdlib=libc++ \
-g3 -Wall -O0
# -std=c++0x -arch x86_64 -stdlib=libc++ \
LDFLAGS = -L/opt/local/lib -L/usr/lib $(pkg-config --libs --cflags opencv) -lm -ljpeg
LDFLAGS = -L/opt/local/lib -L/usr/lib -I/opt/local/include/opencv -I/opt/local/include -L/opt/local/lib -lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_nonfree -lopencv_objdetect -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videostab -lm -ljpeg
.o:
$(CXX) $(CXXFLAGS) -o $@ -c $^
all: $(OBJS)
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o out $(OBJS)
clean:
rm -rf *.o
You can also have the computer guess you the libraries automatically:
CFLAGS = `pkg-config --cflags opencv`
LDFLAGS = `pkg-config --libs opencv` -lm
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With