在64位mac上编译OpenCV代码



我最近继承了一些OpenCV代码。我在我的mac上安装了openCV,内置在XCode中,然后编译并成功运行了我的第一个openCV "hello world"-ish程序。

现在我正试图运行我给出的代码,但我得到的错误使我相信这是原始代码在32位Windows系统上运行的问题,而我的代码在64位Mac上运行。

当我运行Makefile时输入"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)

我得到以下输出…

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

我困惑;这是否意味着我安装的OpenCV是错误的,代码(特别是那些方法)需要改变,或者其他完全?

注意:当我从vision.cpp代码中注释掉问题方法时,一切都编译得很好。

opencv_imgproc添加到您的LDFLAGS:

LDFLAGS = -I/usr/local/include/opencv -lm -lopencv_core -lopencv_highgui -lopencv_video -lopencv_imgproc

下面是一个工作示例:

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

您也可以让计算机自动猜出您的库:

CFLAGS = `pkg-config --cflags opencv` 
LDFLAGS = `pkg-config --libs opencv` -lm

相关内容

  • 没有找到相关文章

最新更新