`g ++编译错误:类型的引用无效初始化,std :: stod()

时间:2016-11-24 06:44:08

标签: c++ c++11 gcc g++

我要安装一些软件包但我在std::stod( )方法中遇到错误。

我的系统是Cent OS。我在gcc-6.2.0目录中安装了带contrib/download_prerequisites的GCC 6.2版本(gmp-4.3.2,isl-0.15,mpc-0.8.1,mpfr-2.4.2) 我有提升-1.62

这是我的gcc配置选项 ./gcc-6.2.0/configure -v --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --prefix=/usr/local/gcc-6.2 --enable-checking=release --enable-languages=c,c++,fortran --disable-multilib --program-suffix=-6.2

所以,现在我的安装流程是关于我想要安装软件包的内容。

[root@cms CASMcode-0.2.0]# scons install
scons: Reading SConscript files ...
rm /usr/local/include/casm
scons: done reading SConscript files.
scons: Building targets ...
Install directory: "include/casm" as "/usr/local/include/casm"
/usr/local/gcc-6.2/bin/g++-6.2 -o src/casm/external/gzstream/gzstream.os -c -DNDEBUG -O3 --std=c++11 -Wno-deprecated-register -Wno-deprecated-declarations -DEIGEN_DEFAULT_DENSE_INDEX_TYPE=long -Wno-unused-parameter -DNDEBUG -O3 -DGZSTREAM_NAMESPACE=gz -fPIC -Iinclude/casm/external/gzstream src/casm/external/gzstream/gzstream.C
cd src/casm/version && sed -e "s|MY_VERSION|0.2.0|g" < version_template.cc > version.cc
/usr/local/gcc-6.2/bin/g++-6.2 -o src/casm/version/version.os -c -DNDEBUG -O3 --std=c++11 -Wno-deprecated-register -Wno-deprecated-declarations -DEIGEN_DEFAULT_DENSE_INDEX_TYPE=long -Wno-unused-parameter -DNDEBUG -O3 -DGZSTREAM_NAMESPACE=gz -fPIC -Iinclude src/casm/version/version.cc
/usr/local/gcc-6.2/bin/g++-6.2 -o src/casm/CASM_global_definitions.os -c -DNDEBUG -O3 --std=c++11 -Wno-deprecated-register -Wno-deprecated-declarations -DEIGEN_DEFAULT_DENSE_INDEX_TYPE=long -Wno-unused-parameter -DNDEBUG -O3 -DGZSTREAM_NAMESPACE=gz -fPIC -Iinclude -I/usr/local/boost_1_62_0/include src/casm/CASM_global_definitions.cc

以下是发生错误消息的位置

In file included from include/casm/casm_io/DataFormatterTools.hh:1291:0,
                 from include/casm/casm_io/DataFormatter_impl.hh:3,
                 from include/casm/casm_io/DataFormatter.hh:757,
                 from include/casm/clex/ConfigIO.hh:4,
                 from src/casm/clex/ConfigIOStrucScore.cc:6:
include/casm/casm_io/DataFormatterTools_impl.hh: In member function 'bool CASM::DataFormatterOperator<ValueType, ArgType, DataObject>::parse_args(const string&)':
include/casm/casm_io/DataFormatterTools_impl.hh:32:33: error: invalid initialization of reference of type 'const wstring& {aka const std::__cxx11::basic_string<wchar_t>&}' from expression of type 'std::__cxx11::string {aka std::__cxx11::basic_string<char>}'
             val = std::stod(ttag);

类似的错误发生在以下代码std::stol(tag)

最后使用此消息停止安装过程

At global scope:
cc1plus: warning: unrecognized command line option '-Wno-deprecated-register'
scons: *** [src/casm/clex/ConfigIOStrucScore.os] Error 1
scons: building terminated because of errors.

我不熟悉C ++,但我听说std::sto()是某种数据类型转换器。 但我不知道如何解决它。我认为这些错误来自旧的gcc版本。但它是如何发生的?

这是include/casm/casm_io/DataFormatterTools_impl.hh:档案。

#include <algorithm>
#include "casm/external/boost.hh"
namespace CASM {

  template<typename ValueType, typename ArgType, typename DataObject>
  bool DataFormatterOperator<ValueType,
       ArgType,
  DataObject>::parse_args(const std::string &_args) {

    if(_args.size() == 0)
      return true;
    if(!m_arg_formatter.empty())
      return false;

    std::vector<std::string> format_tags, subexprs;
    split_formatter_expression(_args, format_tags, subexprs);

    //std::cout << "_args: " << _args << "\n";
    //std::cout << "format_tabs: " << format_tags << "\n"
    //<< "subexprs: '" << subexprs << "'\n";
    for(Index i = 0; i < format_tags.size(); i++) {
      std::string ttag(format_tags[i].size(), ' ');
      std::transform(format_tags[i].cbegin(), format_tags[i].cend(), ttag.begin(), tolower);

      char ch = ttag[0];
      if(boost::is_any_of("-+.0123456789")(ch)) { // tag is a constant number
        if(std::any_of(ttag.cbegin(),
                       ttag.cend(),
                       boost::is_any_of(".e"))) {
          double val;
          try {
            val = std::stod(ttag);
          }
          catch(...) {
            throw std::runtime_error("Unable to parse '" + ttag + "' from subexpression " + _args + "\n");
          }
          m_arg_formatter.push_back(ConstantValueFormatter<double, DataObject>(ttag, val));
        }

我花了很长时间来安装这个包,但我不能。求你帮帮我..


评论中的类似示例

文件

#include <string>


int main() {
    std::string str("1.23");
    double v = std::stod(str);
    (void) v;
    return 0;
}

错误消息

[root@cms ~]# /usr/local/gcc-6.2/bin/g++-6.2 -c -DNDEBUG -O3 --std=c++11 -Wno-deprecated-register -Wno-deprecated-declarations -DEIGEN_DEFAULT_DENSE_INDEX_TYPE=long -Wno-unused-parameter -DNDEBUG -O3 -DGZSTREAM_NAMESPACE=gz -fPIC test.cc
test.cc: In function ‘int main()’:
test.cc:6:29: error: invalid initialization of reference of type ‘const wstring& {aka const std::__cxx11::basic_string<wchar_t>&}’ from expression of type ‘std::__cxx11::string {aka std::__cxx11::basic_string<char>}’
     double v = std::stod(str);
                             ^
In file included from /usr/local/gcc-6.2/include/c++/6.2.0/string:52:0,
                 from test.cc:1:
/usr/local/gcc-6.2/include/c++/6.2.0/bits/basic_string.h:5548:3: note: in passing argument 1 of ‘double std::__cxx11::stod(const wstring&, std::size_t*)’
   stod(const wstring& __str, size_t* __idx = 0)
   ^~~~
At global scope:
cc1plus: warning: unrecognized command line option ‘-Wno-deprecated-register’

0 个答案:

没有答案