Linux CMake 抱怨“CXX 编译器标识未知”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9699930/
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-06 05:10:18  来源:igfitidea点击:

CMake complains "The CXX compiler identification is unknown"

linuxcmake

提问by Stan

I am following this threadand this oneto build my own KDE without a sudo permission. Since there was no Git and CMake installed on the workstation. I just had them both installed under /home/< user>and added /home/< user>/binand /home/< user>/libto both PATH and LD_LIBRARY_PATH. Since KDE build only supports CMake, not configure. So I have to set the prefix via CMake, like this: cmake ~/kde-devel/src/kdelibs -DCMAKE_INSTALL_PREFIX=/home/<user>. At this point I got below error:

我下面这个线程,这一个建立自己的KDE没有须藤权限。由于工作站上没有安装 Git 和 CMake。我只是将它们都安装在/home/<user> 下,并将/home/<user>/bin/home/<user>/lib 添加到 PATH 和 LD_LIBRARY_PATH。由于 KDE 构建仅支持 CMake,不支持配置。所以,我必须通过CMake的设置前缀,像这样:cmake ~/kde-devel/src/kdelibs -DCMAKE_INSTALL_PREFIX=/home/<user>。此时我得到以下错误:

> ~/bin/cmake ~/kde-devel/src/kdelibs -DCMAKE_INSTALL_PREFIX=/home/<user>
-- The CXX compiler identification is unknown
-- Check for working CXX compiler: /home/gnu/bin/c++
-- Check for working CXX compiler: /home/gnu/bin/c++ -- broken
CMake Error at /home/<user>/share/cmake-2.8/Modules/CMakeTestCXXCompiler.cmake:45 (MESSAGE):
  The C++ compiler "/home/gnu/bin/c++" is not able to compile a simple test
  program.

  It fails with the following output:

   Change Dir: /home/<user>/kde-devel/build/kdelibs/CMakeFiles/CMakeTmp



  Run Build Command:/usr/bin/gmake "cmTryCompileExec/fast"
  ...

I checked that there are 2 C++ compilers:

我检查了有 2 个 C++ 编译器:

> where c++
/home/gnu/bin/c++
/usr/bin/c++

Should I set CMake default C++ compiler to /usr/bin/c++? and how? Or is there any way to fix this issue?

我应该将 CMake 默认 C++ 编译器设置为/usr/bin/c++吗?如何?或者有什么办法可以解决这个问题?

采纳答案by arrowd

Your /home/gnu/bin/c++seem to require additional flag to link things properly and CMake doesn't know about that.

/home/gnu/bin/c++似乎需要额外的标志才能正确链接事物,而 CMake 对此一无所知。

To use /usr/bin/c++as your compiler run cmakewith -DCMAKE_CXX_COMPILER=/usr/bin/c++.

/usr/bin/c++用作编译器,请cmake使用-DCMAKE_CXX_COMPILER=/usr/bin/c++.

Also, CMAKE_PREFIX_PATHvariable sets destination dir where your project' files should be installed. It has nothing to do with CMake installation prefix and CMake itself already know this.

此外,CMAKE_PREFIX_PATH变量设置了应该安装项目文件的目标目录。它与 CMake 安装前缀无关,CMake 本身已经知道这一点。

回答by jason

I just had this problem setting up my new laptop. The issue for me was that my toolchain (CodeSourcery) is 32bit and I had not installed the 32bit libs.

我刚刚在设置我的新笔记本电脑时遇到了这个问题。我的问题是我的工具链 (CodeSourcery) 是 32 位的,我还没有安装 32 位的库。

sudo apt-get install ia32-libs

回答by Ramzes

Run apt-get install build-essentialon your system.

apt-get install build-essential在您的系统上运行。

This package depends on other packages considered to be essential for builds and will install them. If you find you have to build packages, this can be helpful to avoid piecemeal resolution of dependencies.

这个包依赖于被认为对构建必不可少的其他包,并将安装它们。如果您发现必须构建包,这有助于避免依赖项的零碎解决。

See this pagefor more info.

有关更多信息,请参阅此页面