我有一个运行良好的 opencv 项目。今天我已将我的 OS X lion 升级到 Maverick,但 imwrite 功能出现以下错误:
Undefined symbols for architecture x86_64:
"cv::imwrite(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cv::_InputArray const&, std::__1::vector<int, std::__1::allocator<int> > const&)", referenced from:
_main in Hello.o
ld: symbol(s) not found for architecture x86_64
我不得不说其他 opencv 函数仍在工作(例如 cvWaitKey()、cvShowImage 等),但 imwrite 和 imread 不再工作了。
您可以在下面看到我使用的 makefile:
CXX = g++
CXXFLAGS = -O2 -g -Wall -fmessage-length=0
CPPFLAGS = -I/usr/local/Cellar/opencv/2.4.6.1/include
OBJS = Hello.o
LDFLAGS = -L/usr/local/Cellar/opencv/2.4.6.1/lib
LDLIBS = -lopencv_core -lopencv_imgproc -lopencv_calib3d -lopencv_video \
-lopencv_features2d -lopencv_ml -lopencv_highgui -lopencv_objdetect \
-lopencv_contrib -lopencv_legacy -lopencv_gpu
TARGET = Hello
.PHONY: all
all: $(TARGET)
$(TARGET): $(OBJS)
$(CXX) $(LDFLAGS) $^ $(LDLIBS) -o $@
.PHONY: clean
clean:
rm -f $(OBJS) $(TARGET)
解决方案: 我通过安装opencv 2.4.3解决了这个问题。您可能会在我添加的答案中找到更多详细信息。