10
votes

I'm trying to install OpenCV on my Mac by following this link

However, when I type cmake -G "Unix Makefiles" .. on my terminal, this error is printed.

-- The CXX compiler identification is unknown -- The C compiler identification is unknown -- Check for working CXX compiler: /usr/bin/c++ -- Check for working CXX compiler: /usr/bin/c++ -- broken CMake Error at /opt/local/share/cmake-3.0/Modules/CMakeTestCXXCompiler.cmake:54 (message): The C++ compiler "/usr/bin/c++" is not able to compile a simple test program.

It fails with the following output:

Change Dir: /Users/kwmaeng/Desktop/opencv/build/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/make" "cmTryCompileExec653545098/fast"

make: error: unable to find utility "make", not a developer tool or in PATH

CMake will not be able to correctly generate this project. Call Stack (most recent call first): CMakeLists.txt:56 (project)

-- Configuring incomplete, errors occurred! See also "/Users/kwmaeng/Desktop/opencv/build/CMakeFiles/CMakeOutput.log". See also "/Users/kwmaeng/Desktop/opencv/build/CMakeFiles/CMakeError.log".

So I checked CMakeError.log, and this is the content

Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed. Compiler: /usr/bin/c++ Build flags: Id flags:

The output was: 72 xcodebuild: error: SDK "/Volumes/MAC/dev/adt-bundle-mac-x86_64-20131030/sdk" cannot be located. c++: error: unable to find utility "clang++", not a developer tool or in PATH ...(blah blah)

Weird thing is, /Volumes/MAC/dev/adt-bundle-mac-x86_64-20131030/sdk is where my Android SDK had been installed, and it is deleted now, so there are no such folder anymore. Is the error occurring because cmake is referring to invalid path that does not exist anymore?? Why is cmake referring the location of android sdk in the first place?? Does it even matter to opencv??

I googled for hours but not much help was found. Please help me if you have any ideas.

Thanks in advance.

6
Do you actually have a C++ compiler installed, i.e. have you installed Xcode and/or the developer command line tools ?Paul R
I suggest you use the gui of CMake (cmake-gui). The first time you configure, you can also specify the path to the compiler.Antonio
Have you tried setting the path to the compiler?: -DCMAKE_CXX_COMPILER=/usr/bin/c++0x499602D2
I have installed Xcode so I have a compiler. I'll try specifing the path to the compiler as soon as I get home.kwmaeng
@kw this is not a forum, so no [solved] in titles. See faq. Here, when somebody, including yourself, answers your question and provides you with a solution to your problem, you're supposed to click the checkmark next to the answer.dandan78

6 Answers

6
votes

Thanks to everybody's help, I was able to solve my issue.

For other people who may suffer from the same problem in the future, this is what I did:

it was because my $PATH was messed up (I think it happened when I tried to add Android SDK to $PATH)

I cleared the .bash_profile and added C++ and make and /opt/local/bin, /opt/local/sbin

like this

export PATH=$PATH:/opt/local/bin:/opt/local/sbin:/usr/bin/c++:/usr/bin/make

and it worked like charm.

4
votes

I had the same problem - what worked was to remove the command line tools:

rm -rf /Library/Developer/CommandLineTools

Then reinstall the command line tool:

xcode-select --install

Who knows what that script is doing...and I don't have time to investigate so there you go...

1
votes

I found yet another solution: putting set(CMAKE_C_COMPILER gcc) at the very top of my CMakeLists.txt. For reference, I got this error right after installing a CLion update.

Here's my final CMakeLists.txt:

set(CMAKE_C_COMPILER gcc)
cmake_minimum_required(VERSION 3.6)
project(...)

set(CMAKE_CXX_STANDARD 11)

set(SOURCE_FILES XXX.cpp)
add_executable(... ${SOURCE_FILES})
0
votes

For me, my first problem was that I didn't have the Xcode command line tools..So I got those (xcode-select --install in terminal), and I still had the problem. The solution? Close the terminal window and create a new one. Then, voila!

0
votes

I have also experienced this problem and have resolved it.

The code is:

yum -y install gcc-c++
0
votes

I also come across this issue, I have fixed it by setting the correct CXXFLAGS and CPPFLAGS. I think you should also check it.

One simple solution would be:

CPPFLAGS := $(CPPFLAGS) $(CFLAGS)
CXXFLAGS := $(CXXFLAGS) $(CFLAGS)