cmake关于自定义gcc安装路径报错问题

4 篇文章 0 订阅

linux服务器自定义安装gcc4.8.2为支持学习C++11,使用到cmake时总是报错如下:

-- The C compiler identification is unknown
-- The CXX compiler identification is GNU 4.8.2
-- Check for working C compiler: /home/**/gcc11/gcc-4.8.2/bin/g++
-- Check for working C compiler: /home/**/gcc11/gcc-4.8.2/bin/g++ -- broken
CMake Error at /usr/local/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:52 (MESSAGE):
  The C compiler "/home/**//gcc11/gcc-4.8.2/bin/g++" is not able to
  compile a simple test program.

  It fails with the following output:

   Change Dir: /home/**/study/c++11/thread/threadpool/build/CMakeFiles/CMakeTmp

 

  Run Build Command:/usr/bin/gmake "cmTryCompileExec3281654297/fast"

  /usr/bin/gmake -f CMakeFiles/cmTryCompileExec3281654297.dir/build.make
  CMakeFiles/cmTryCompileExec3281654297.dir/build

  gmake[1]: Entering directory
  `/DATA/**/study/c++11/thread/threadpool/build/CMakeFiles/CMakeTmp'

  /usr/local/bin/cmake -E cmake_progress_report
  /home/**/study/c++11/thread/threadpool/build/CMakeFiles/CMakeTmp/CMakeFiles
  1

  Building C object
  CMakeFiles/cmTryCompileExec3281654297.dir/testCCompiler.c.o

  /home/**/gcc11/gcc-4.8.2/bin/g++ -o
  CMakeFiles/cmTryCompileExec3281654297.dir/testCCompiler.c.o -c
  /home/**/study/c++11/thread/threadpool/build/CMakeFiles/CMakeTmp/testCCompiler.c


 
  /home/**/study/c++11/thread/threadpool/build/CMakeFiles/CMakeTmp/testCCompiler.c:2:3:
  error: #error "The CMAKE_C_COMPILER is set to a C++ compiler"

   # error "The CMAKE_C_COMPILER is set to a C++ compiler"
     ^

  gmake[1]: Leaving directory
  `/DATA/**/study/c++11/thread/threadpool/build/CMakeFiles/CMakeTmp'

  gmake[1]: *** [CMakeFiles/cmTryCompileExec3281654297.dir/testCCompiler.c.o]
  Error 1

  gmake: *** [cmTryCompileExec3281654297/fast] Error 2

 

 

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


-- Configuring incomplete, errors occurred!

 

如上报错,则是由于编译时找不到对应的gcc的4.8.2的相关文件,就算环境变量中带有gcc4.8.2的路径,也必须在CMakeLists.txt中指出:如下所示,添加这两个set设置,则cmake成功

set(CMAKE_C_COMPILER "/DATA/**/gcc11/gcc-4.8.2/bin/gcc")
set(CMAKE_CXX_COMPILER "/DATA/**/gcc11/gcc-4.8.2/bin/g++")

完整CMakeLists.txt:

cmake_minimum_required(VERSION 2.8)

set(CMAKE_C_COMPILER "/DATA/**/gcc11/gcc-4.8.2/bin/gcc")
set(CMAKE_CXX_COMPILER "/DATA/**/gcc11/gcc-4.8.2/bin/g++")

project(demo)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread")

aux_source_directory(. DIR_SRCS)
add_executable(11ThreadPool ${DIR_SRCS})

修改上述内容,即可用。

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值