“The C++ compiler ”/usr/bin/c++“ is not able to compile a simple test program.” When trying to install OpenCV

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.

  • How to access Swift-objects from a c++ class?
  • Algorithm for creating rounded corners in a polygon
  • Expression pattern of type 'String' cannot match values of type 'NSStoryboardSegue.Identifier
  • Variably modified array at file scope
  • Swift error: Cannot assign to immutable value
  • Why can't I compile this command-line OpenCV Mac application?
  • — 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 Solutions Collect From Internet About ““The C++ compiler ”/usr/bin/c++“ is not able to compile a simple test program.” When trying to install OpenCV”

    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.

    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…

    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)

    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!

    I have also experienced this problem and have resolved it.

    The code is:

    yum -y install gcc-c++
    

    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})