【问题标题】:no matching function for call to ‘std::basic_ifstream<char>::basic_ifstream(std::__cxx11::string&)’ ifstream myfile(filename);没有匹配函数调用‘std::basic_ifstream<char>::basic_ifstream(std::__cxx11::string&)’ ifstream myfile(filename);
【发布时间】:2020-05-01 17:40:34
【问题描述】:

我正在使用 Cmake 和 Ctest 来尝试在 Travis CI 上测试我的代码。如果我使用 cmake 在本地进行测试,我将不会遇到任何错误,并且我可以进行测试。当通过 Travis CI 运行测试时,我得到了很多错误,比如这个:

error: no matching function for call to ‘std::basic_ifstream<char>::basic_ifstream(std::__cxx11::string&)’

ifstream myfile(filename);

文件名是一个字符串。 travis 是否运行与我的本地设置不同的版本编译器?

【问题讨论】:

  • 确保包含&lt;fstream&gt;
  • 可能是一个版本的东西。旧版本的标准库只接受 const char* 那里。
  • 你知道如何在 Travis CI 上使用更新的版本吗?
  • 你的代码是 C++ >= 11,显然你应该告诉 Travis 你需要一个特定的编译器(和/或标志)。

标签: c++ cmake ctest


【解决方案1】:

需要更新 Travis CI C++ 版本。

这里是完整的 .travis.yml

language: cpp
compiler: gcc

os: linux

addons:
  apt:
    sources:
      - ubuntu-toolchain-r-test 
    packages:
      - g++-7
compiler:
  - clang
script:
- export CC=gcc-7
- export CXX=g++-7
- gcc -v && g++ -v && cmake --version
- cmake ./Computing\ project/Test\ Mains/

【讨论】:

    猜你喜欢
    • 2020-07-13
    • 1970-01-01
    • 1970-01-01
    • 2013-07-11
    • 2018-12-05
    • 1970-01-01
    • 2018-03-10
    • 2020-07-14
    • 2018-03-11
    相关资源
    最近更新 更多