Cmake 中g++ gcc 编译器版本问题

环境:

  1. centos7
  2. 手动升级gcc-4.9.0
  3. PATH环境变量
[root@S21759 log4cplus]# echo $PATH
/usr/local/gcc-4.9.0/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/usr/local/cmake-3.15.4/bin/

编译log4cplus静态库,并使用
编译命令:

  ./configure CXXFLAGS="-fPIC" --prefix=$(pwd)/../__INSTALL --enable-static
  make && make install

应用CMakeLists.txt中不加

SET(CMAKE_CXX_COMPILER      "g++")

报如下错误:

../../../../SDK/Lib/liblog4cplus.a(liblog4cplus_la-fileappender.o): In function `log4cplus::preprocessFilenamePattern(std::string const&, log4cplus::DailyRollingFileSchedule&)':
fileappender.cxx:(.text+0x7c08): undefined reference to `std::__throw_out_of_range_fmt(char const*, ...)'
../../../../SDK/Lib/liblog4cplus.a(liblog4cplus_la-patternlayout.o): In function `log4cplus::pattern::LoggerPatternConverter::convert(std::string&, log4cplus::spi::InternalLoggingEvent const&)':
patternlayout.cxx:(.text+0x304): undefined reference to `std::__throw_out_of_range_fmt(char const*, ...)'
../../../../SDK/Lib/liblog4cplus.a(liblog4cplus_la-patternlayout.o): In function `log4cplus::pattern::BasicPatternConverter::convert(std::string&, log4cplus::spi::InternalLoggingEvent const&)':
patternlayout.cxx:(.text+0xaac): undefined reference to `std::__throw_out_of_range_fmt(char const*, ...)'
../../../../SDK/Lib/liblog4cplus.a(liblog4cplus_la-patternlayout.o): In function `log4cplus::pattern::PatternConverter::formatAndAppend(std::ostream&, log4cplus::spi::InternalLoggingEvent const&)':
patternlayout.cxx:(.text+0xe1e): undefined reference to `std::__throw_out_of_range_fmt(char const*, ...)'
../../../../SDK/Lib/liblog4cplus.a(liblog4cplus_la-patternlayout.o): In function `log4cplus::pattern::PatternParser::extractOption()':
patternlayout.cxx:(.text+0x200a): undefined reference to `std::__throw_out_of_range_fmt(char const*, ...)'
../../../../SDK/Lib/liblog4cplus.a(liblog4cplus_la-property.o):property.cxx:(.text+0x10c4): more undefined references to `std::__throw_out_of_range_fmt(char const*, ...)' follow
collect2: error: ld returned 1 exit status

加上后编译正常

总结:
CMakeLists中使用指定版本的编译器需要满足如下条件:

  1. 在环境变量中可以找到gcc和g++的执行目录,及PATH环境变量中
  2. 在CMakeLists中,添加如下设置
    SET(CMAKE_CXX_COMPILER “g++”)
    SET(CMAKE_C_COMPILER “gcc”)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值