“C++ 编译器“/usr/bin/c++”无法编译简单的测试程序。” 尝试安装 OpenCV 时

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25976001/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 11:29:00  来源:igfitidea点击:

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

c++xcodemacosopencv

提问by kwmaeng

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

我正在尝试按照此链接在我的 Mac 上安装 OpenCV

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

但是,当我cmake -G "Unix Makefiles" ..在终端上输入时,会打印此错误。

-- 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".

-- CXX 编译器标识未知 -- C 编译器标识未知 -- 检查工作的 CXX 编译器:/usr/bin/c++ -- 检查工作的 CXX 编译器:/usr/bin/c++ -- 损坏的 CMake 错误在/opt/local/share/cmake-3.0/Modules/CMakeTestCXXCompiler.cmake:54(消息):C++ 编译器“/usr/bin/c++”无法编译简单的测试程序。

它失败并显示以下输出:

更改目录:/Users/kwmaeng/Desktop/opencv/build/CMakeFiles/CMakeTmp

运行构建命令:"/usr/bin/make" "cmTryCompileExec653545098/fast"

make:错误:无法找到实用程序“make”,不是开发人员工具或在 PATH 中

CMake 将无法正确生成此项目。调用堆栈(最近调用优先):CMakeLists.txt:56(项目)

-- 配置不完整,出现错误!另请参阅“/Users/kwmaeng/Desktop/opencv/build/CMakeFiles/CMakeOutput.log”。另请参阅“/Users/kwmaeng/Desktop/opencv/build/CMakeFiles/CMakeError.log”。

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

所以我检查了 CMakeError.log,这是内容

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)

编译CXX编译器识别源文件“CMakeCXXCompilerId.cpp”失败。编译器:/usr/bin/c++ 构建标志:Id 标志:

输出为:72 xcodebuild: error: SDK "/Volumes/MAC/dev/adt-bundle-mac-x86_64-20131030/sdk" 无法定位。C++:错误:无法找到实用程序“clang++”,不是开发人员工具或在 PATH ...(等等)

Weird thing is, /Volumes/MAC/dev/adt-bundle-mac-x86_64-20131030/sdkis 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??

奇怪的是,/Volumes/MAC/dev/adt-bundle-mac-x86_64-20131030/sdk是我的Android SDK安装的地方,现在删除了,所以不再有这样的文件夹了。发生错误是因为 cmake 指的是不再存在的无效路径?为什么 cmake 首先指的是 android sdk 的位置?opencv 甚至重要吗??

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

我用谷歌搜索了几个小时,但没有找到太多帮助。如果您有任何想法,请帮助我。

Thanks in advance.

提前致谢。

采纳答案by kwmaeng

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 $PATHwas messed up (I think it happened when I tried to add Android SDK to $PATH)

那是因为我$PATH搞砸了(我认为这是在我尝试将 Android SDK 添加到 时发生的$PATH

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

我清除.bash_profile并添加了 C++ 和 make /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.

它的作用就像魅力一样。

回答by cayossarian

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...

谁知道那个脚本在做什么......我没有时间调查所以你去......

回答by no?????z???

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.

我找到了另一个解决方案:放在set(CMAKE_C_COMPILER gcc)我的CMakeLists.txt. 作为参考,我在安装 CLion 更新后立即收到此错误。

Here's my final CMakeLists.txt:

这是我的决赛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})

回答by zilongshanren

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

我也遇到过这个问题,我通过设置正确的 CXXFLAGS 和 CPPFLAGS 来修复它。我想你也应该检查一下。

One simple solution would be:

一种简单的解决方案是:

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

回答by ALamp

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

对我来说,我的第一个问题是我没有 Xcode 命令行工具..所以我得到了那些(xcode-select --install在终端中),但我仍然遇到了问题。解决方案?关闭终端窗口并创建一个新窗口。然后,瞧!

回答by fxxph

I have also experienced this problem and have resolved it.

我也遇到过这个问题并且已经解决了。

The code is:

代码是:

yum -y install gcc-c++