LoginSignup
3
4

More than 5 years have passed since last update.

CocoaPodsでOpenCV2.4を使う方法

Last updated at Posted at 2016-01-05

'list' file not found について

pod installしてimport <opencv2/opencv.hpp>してビルドだ!
あれ、何このエラー。

検索すると、
#ifdef __cplusplusで回避せよとの回答がたくさん出てくる。
出てきますが、Podの書き換えはダメですよね。どう考えても。

#import <opencv2/opencv.hpp>は、必ず.mmファイルに書くようにしましょう。
いずれにせよObjective-C++でないと使えないし…。

.hファイルに書くと、Bridging-Header.hに書いた時にCのヘッダとしてコンパイルされるので上のエラーがまた出る。
Swiftで使いたいなら.hにはC++のコードはいれない。

勿論Objective-C++からしか呼ばないヘッダファイルならそこに書いてもOK。

バージョンについて

結論から言うと2.4.12.3をつかう。
pod installするとビルドが走るのでめちゃめちゃ時間がかかるが、気長に待つ。
pod install --verboseすると進行していることはわかるので心臓に優しい。
git cloneの進行状況も見せてほしいよなぁ、正直。

2.4.10まではバイナリ配付だが、2.4.9UIImageToMatがオーバーリリースしており、何回か呼び出すと以下の様なエラーを吐いて落ちる。
修正コミット

Assertion failed: (!space->is_singleton), function color_space_dealloc, file ColorSpaces/color-space.c, line 102.

修正コミットが2.4.11で反映されているっぽいのでそれ未満は論外だが、
2.4.10に関してはそもそも以下のエラーが出てビルドが通らない。
いい加減にして欲しい。
stackoverflowで修正コミットを投げてくれたらしい人がいた。多謝。
そのstackoverlow

Undefined symbols for architecture arm64:
  "_jpeg_free_small", referenced from:
      _free_pool in opencv2(jmemmgr.o)
      _self_destruct in opencv2(jmemmgr.o)
  "_jpeg_mem_available", referenced from:
      _realize_virt_arrays in opencv2(jmemmgr.o)
  "_jpeg_free_large", referenced from:
      _free_pool in opencv2(jmemmgr.o)
  "_jpeg_open_backing_store", referenced from:
      _realize_virt_arrays in opencv2(jmemmgr.o)
  "_jpeg_get_large", referenced from:
      _alloc_large in opencv2(jmemmgr.o)
      _alloc_barray in opencv2(jmemmgr.o)
  "_jpeg_mem_term", referenced from:
      _jinit_memory_mgr in opencv2(jmemmgr.o)
      _self_destruct in opencv2(jmemmgr.o)
  "_jpeg_mem_init", referenced from:
      _jinit_memory_mgr in opencv2(jmemmgr.o)
  "_jpeg_get_small", referenced from:
      _jinit_memory_mgr in opencv2(jmemmgr.o)
      _alloc_small in opencv2(jmemmgr.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

2.4.11以降ならどうせビルド走るし、だったら最新で良いよね。という話。
2.4.122.4.12.3では現状問題は発生していない。

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4