6

Trying to compile opencv on my Mac from source.

I have following CMakeCache.txt: http://pastebin.com/KqPHjBx0

I make ccmake .., press c, then g. Than I make sudo make -j8: http://pastebin.com/cJyr1cEd

Than I make sudo make install: http://pastebin.com/W77syYBj

And than I make import cv in python and get "Segmentation faul" with this stacktrace: http://pastebin.com/gegYAK1u

I don't know what could be useful to help me, pls. ask, I'll get it.

Daenyth
  • 35,856
  • 13
  • 85
  • 124
Aleksandr Motsjonov
  • 1,230
  • 3
  • 14
  • 25

4 Answers4

8

I had a same situation and resolved the following steps.

In ccmake(ccmake -G "Unix Makefiles" .), toggle to the advanced mode pressing t.

change PYTHON_LIBRARY value to /opt/local/lib/libpython2.6.dylib and PYTHON_INCLUDE_DIR to /opt/local/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6.

Note that the specific path depends, of course, what version of Python you are using (2.6 or 2.7 etc.). Also, if you are using the system Python, instead of MacPorts (which is in /opt), then you probably want PYTHON_LIBRARY to be /usr/lib/libpython2.6.dylib

Community
  • 1
  • 1
masa
  • 81
  • 1
  • 2
  • this seemed to fix it for me, even though the `'make install'` errored out. go figure. – crizCraig Feb 27 '12 at 19:45
  • I had the same error, but couldn't understand this answer. But typing `sudo port select --set python python27` fixed the segfault for me. – Richard Aug 22 '13 at 15:28
  • In my case, I don't have MacPorts Python, but rather the python.org Python. I just rewrote the symlink at `/usr/lib/libpython2.7.dylib` to point to `/Library/Frameworks/Python.framework/Versions/2.7/Python` instead of `/System/Library/Frameworks/Python.framework/Versions/2.7/Python`. – jab Apr 10 '14 at 04:52
1

From your logs, you seem to use MacPorts and python 2.6.

opencv will compile fine on this framework:

sudo port install  opencv +python26

be sure to have py26-numpy installed to have support for basic functions such as cv.fromarray :

sudo port install py26-numpy

means that your problem has been solved by the MacPorts community. is it a problem of the latest source? the version you compile is the one (opencv 2.2.0) used by macports.

Your question is about compiling from source. Looking at the portfile linked to that you'll be able to locate your problem. to find the Portfile, do:

port file opencv

or directly

sudo port edit  opencv

this will list all configuration flags necessary for a working openCV.

meduz
  • 3,903
  • 1
  • 28
  • 40
  • I tried different variations already and many of them failed with different results. I have messy system right now. ---- I have python_select installed. It has 2 variants of python26: python26-apple and python26. If -apple one selected I have situation described in this post. --- Having selected second I have this http://pastebin.com/ve7wjFy5. --- Here is what import paths python26 has: http://pastebin.com/1kggWJZB Python26-apple has: http://pastebin.com/eDmXfpgg – Aleksandr Motsjonov Mar 10 '11 at 19:31
  • Just in case - here where i get opencv mentioned under /opt/: http://pastebin.com/Qij5kuFt --- Here is where I have cv.so already: http://pastebin.com/Di8MvSJj – Aleksandr Motsjonov Mar 10 '11 at 19:36
0

Typing:

sudo port select --set python python27

fixed the segfault for me.

Richard
  • 62,943
  • 126
  • 334
  • 542
0

The problem is simple, macports did rewrote cv.so in ~/usr/lib

if you installed OPENCV using

sudo port install  opencv +python26

type

sudo port select --set python python26

if you installed OPENCV using

sudo port install  opencv +python27

type

sudo port select --set python python27

The "bug" is that python2.7 interpreter is trying to open python2.6 pre-compiled binary that gives seg fault 11 (or vice versa)

The nevereinding problem with opencv is that it does not have source code, just binaries that are stongly dependent on which compiler there were built on (which platform etc.)

Jan Cajthaml
  • 403
  • 3
  • 13