-1

I was trying to install opencv for python using this link. After running the Cmake command, it exited with errors stating C++11 is not supported Although I have Xcode installed. I Also tried forcing Cmake to use C++ 11 using $ set(CMAKE_CXX_STANDARD 11) (because my Cmake version is 3.10.2), but I got this error:

syntax error near unexpected token `CMAKE_CXX_STANDARD'

Moreover, I tried installing gcc to check if my system supports the C++ 11 compiler through this link, where again I ran into terminal errors stating ./fixincludes: No such file or directory after running $ make install . What should I do?

  • 1
    Can you run gcc --version in your terminal? what's the version number? – Stefano Buora Feb 10 '18 at 16:51
  • @StefanoBuora I think it is 4.2.1 according to the first line, or am I reading it wrong? Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM version 9.0.0 (clang-900.0.39.2) Target: x86_64-apple-darwin17.3.0 Thread model: posix InstalledDir: /Library/Developer/CommandLineTools/usr/bin – Ghazal Sahebzamani Feb 10 '18 at 16:56
  • The version sounds good, I've got the same with the latest Xcode version installed – Stefano Buora Feb 10 '18 at 17:01
  • gcc 4.2 is *way* older than C++11. Of course that does not work. – Baum mit Augen Feb 10 '18 at 17:06
  • If you have xcode you probably have a recent version of clang which should support C++11, 14 and probably even 17. Installing gcc isn't a good idea, but if you do do that, pick a version that isn't ancient. – juanchopanza Feb 10 '18 at 17:11
  • You are right, I'm using CLang (not gcc) in my projects and it works nicely with C++11 constructs – Stefano Buora Feb 10 '18 at 17:14
  • https://gcc.gnu.org/projects/cxx-status.html, sais that, if you want to use C++11 constructs, it should be gcc 4.8 or greater – Stefano Buora Feb 10 '18 at 17:16
  • I think you should read this: https://stackoverflow.com/questions/7031126/switching-between-gcc-and-clang-llvm-using-cmake – Stefano Buora Feb 10 '18 at 17:16
  • @juanchopanza I have Xcode installed, so why do I get "C++ 11 not supported" with Cmake? – Ghazal Sahebzamani Feb 10 '18 at 17:38
  • @Ghazal.S No idea. What does `c++ --version` give you in the command line? – juanchopanza Feb 10 '18 at 17:39
  • @StefanoBuora Thanks. So now I should install gcc 4.8 or higher. As I mentioned I went through this tutorial https://github.com/cmangos/issues/wiki/Getting-a-C--11-compiler-on-Mac-OS-X, but I got stuck after getting this error ./fixincludes: No such file or directory . What should I do now? – Ghazal Sahebzamani Feb 10 '18 at 17:42
  • At which step of the wiki page have you got the error? – Stefano Buora Feb 10 '18 at 17:46
  • @Ghazal.S From the second comment, you already have a recent version of clang++. Unless OpenCV requires that you install gcc, which I seriously doubt, don't do it. Also, gcc 4.8 is ancient anyway. It would make no sense to install that. Better look up how to build opencv on mac OS. – juanchopanza Feb 10 '18 at 17:51
  • @StefanoBuora I got it after step 9 (make install) – Ghazal Sahebzamani Feb 10 '18 at 18:18
  • @juanchopanza Yes, I guess so. I also did a bit of searching and it turns out I don't have any gcc installed (according to my second comment) unlike the latest version of clang ++. Ok I won't install gcc, but I know some part of my cmake for opencv needs c++ 11, and that's where I thought I should install gcc to support it. – Ghazal Sahebzamani Feb 10 '18 at 18:22
  • 1
    why didn't you use homebrew (you installed it in your tutorial) for installing GCC? it installs the last version of GCC by default. – Parham Alvani Feb 10 '18 at 18:55
  • @ParhamAlvani Hello Parham! (We met on Noor's Birthday :D) I have already installed homebrew, but I don't know how to use it for installing gcc...could you please help me? I also think my whole problem is that I can't enable c++ on cmake. I tried running this command in the terminal: set(CMAKE_CXX_STANDARD 11) but it doesn't work out as I get the abovementioned error.(syntax error near unexpected token `CMAKE_CXX_STANDARD') – Ghazal Sahebzamani Feb 10 '18 at 19:41
  • Hello :D. for installing GCC using homebrew use `brew install gcc`. after installing GCC I think your problem must be solved. – Parham Alvani Feb 10 '18 at 20:59
  • @ParhamAlvani Thanks, but unfortunately it didn't work as well – Ghazal Sahebzamani Feb 10 '18 at 22:36
  • Homebrew installation failed or GCC installed successfully and cmake failed again? – Parham Alvani Feb 11 '18 at 06:32
  • @ParhamAlvani GCC installed successfully and cmake failed again due to the same error (c++ 11 not supported). – Ghazal Sahebzamani Feb 11 '18 at 09:08

2 Answers2

0

Adrian has a more recent blog post on compiling OpenCV for the macOS. The instructions work both for 3.3.0 and 3.3.1.

seamus
  • 61
  • 2
  • 3
0

First open python by python2 or python3 command in terminal after type import cv2 and everything is right now.

mrr
  • 372
  • 1
  • 3
  • 15