- 1.在OpenCV的官网(http://opencv.org)下载OpenCV之后,使用XCode新建工程,然后将下载下来的OpenCV库添加到工程中。- 在添加的过程中,如果顺序是点击XCode工程中的Build Phases,然后点击 Link Binary with Libraries中的+号,然后点击 Add other,找到下载好的OpenCV库加入的话,这时候虽然在工程会显示
ld: framework not found opencv2
clang: error: linker command failed with exit code 1 (use -v to see invocation),找不到OpenCV库,这时候在finder中找到打开工程的目录,会发现在finder中并没有将OpenCV库添加进来。
,原因是通过这种方式添加进来的默认是不拷贝到工程中的,所以在编译的时候会找不到库。
- 可以将下载好的库,通过拖拽的方式添加到工程中,拖拽的时候选择拷贝即可。OpenCV库不需要依赖其余的库,所以不需要添加依赖库,也不需要进行其他的配置。
- 2.将OpenCV所需的依赖库添加到项目中。
libc++.tbd
AVFoundation.framework
CoreImage.framework
CoreGraphics.framework
QuartzCore.framework
Accelerate.framework
如果要使用摄像头做视频处理,还需要添加以下两个依赖库:
CoreVideo.framework
CoreMedia.framework
AssetsLibrary.framework
- 3.可能出现如下错误:
Undefined symbols for architecture x86_64:
"_jpeg_free_large", referenced from:
_free_pool in opencv2(jmemmgr.o)
"_jpeg_free_small", referenced from:
_free_pool in opencv2(jmemmgr.o)
_self_destruct in opencv2(jmemmgr.o)
"_jpeg_get_large", referenced from:
_alloc_large in opencv2(jmemmgr.o)
_alloc_barray in opencv2(jmemmgr.o)
"_jpeg_get_small", referenced from:
_jinit_memory_mgr in opencv2(jmemmgr.o)
_alloc_small in opencv2(jmemmgr.o)
"_jpeg_mem_available", referenced from:
_realize_virt_arrays in opencv2(jmemmgr.o)
"_jpeg_mem_init", referenced from:
_jinit_memory_mgr in opencv2(jmemmgr.o)
"_jpeg_mem_term", referenced from:
_jinit_memory_mgr in opencv2(jmemmgr.o)
_self_destruct in opencv2(jmemmgr.o)
"_jpeg_open_backing_store", referenced from:
_realize_virt_arrays in opencv2(jmemmgr.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
解决办法:
安装:libjpeg-turbo.dmg : https://sourceforge.net/projects/libjpeg-turbo/files/1.4.0/
在终端运行:lipo -info /opt/libjpeg-turbo/lib/libjpeg.a 将会出现以下内容:
Architectures in the fat file: /opt/libjpeg-turbo/lib/libjpeg.a are: i386 x86_64 armv6 armv7 armv7s arm64
然后将/opt/libjpeg-turbo/lib/libjpeg.a 加到你的工程里面
网友评论