camera_calibration.cpp: undefined reference to cv::read

asked 2018-03-13 01:47:58 -0600

spamrefuse gravatar image

updated 2018-03-13 06:59:32 -0600

I have opencv-3.4.1 on Ubuntu 16.04, on which OpenCV itself compiles fine.

I want to use the camera_calibration from the tutorial:


As the Makefile, I copied opencv-3.4.1/samples/cpp/example_cmake/Makefile

and modified it into:

CXX ?= g++

CXXFLAGS += -c -Wall $(shell pkg-config --cflags opencv)
LDFLAGS += $(shell pkg-config --libs --static opencv)

all: camera_calibration

camera_calibration: camera_calibration.o; $(CXX) $< -o $@ $(LDFLAGS)

%.o: %.cpp; $(CXX) $< -o $@ $(CXXFLAGS)

clean: ; rm -f camera_calibration.o camera_calibration

However, I get following error when doing the 'make':

$ make
g++ camera_calibration.o -o camera_calibration -L/usr/local/lib -lopencv_shape -lopencv_objdetect -lopencv_videostab -lopencv_stitching -lopencv_calib3d -lopencv_superres -lopencv_photo -lopencv_features2d -lopencv_video -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_imgproc -lopencv_ml -lopencv_flann -lopencv_core -ldl -lm -lpthread -lrt -ltbb
camera_calibration.o: In function `void cv::operator>><std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(cv::FileNode const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)':
camera_calibration.cpp:(.text+0x251): undefined reference to `cv::read(cv::FileNode const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
collect2: error: ld returned 1 exit status
Makefile:8: recipe for target 'camera_calibration' failed
make: *** [camera_calibration] Error 1

This error goes away when I comment out line 266 in camera_calibration.cpp

//fs["Settings"] >> s;

The error also seems related to the definition of the read function on line 240:

static inline void read(const FileNode& node, Settings& x, const Settings& default_value = Settings())
        x = default_value;

I'm still at a loss as to why camera_calibration.cpp does not compile....

Thanks! -S.

edit retag flag offensive close merge delete