【问题标题】:"Invalid arguments" when porting C++ code to Android将 C++ 代码移植到 Android 时出现“无效参数”
【发布时间】:2014-01-18 15:11:43
【问题描述】:

作为 NDK 工作的一部分,我正在尝试将以下 C++ 代码移植到 Android:

#include <fstream>

// ...

inline void trim(string & str, const string & delim = " \t\r\n")
{
    string::size_type pos = str.find_last_not_of(delim);
    if(pos == string::npos) str.erase(str.begin(), str.end());
    else
    {
        str.erase(pos+1);
        pos = str.find_first_not_of(delim);
        if(pos != string::npos) str.erase(0, pos);
    }
}

我在str.erase(pos+1);str.erase(0, pos) 收到以下消息:

Invalid arguments '
Candidates are:
std::basic_string<char,std::char_traits<char>,std::allocator<char>> & erase(?, ?)
__gnu_cxx::__normal_iterator<char *,std::basic_string<char,std::char_traits<char>,std::allocator<char>>>    erase(__gnu_cxx::__normal_iterator<char *,std::basic_string<char,std::char_traits<char>,std::allocator<char>>>)
__gnu_cxx::__normal_iterator<char *,std::basic_string<char,std::char_traits<char>,std::allocator<char>>>     erase(__gnu_cxx::__normal_iterator<char *,std::basic_string<char,std::char_traits<char>,std::allocator<char>>>,     __gnu_cxx::__normal_iterator<char *,std::basic_string<char,std::char_traits<char>,std::allocator<char>>>)
'

我尝试了here 的建议,但没有帮助。相反,现在我收到了#include &lt;fstream&gt; 的新消息:

Unresolved inclusion: <fstream>

我需要做什么来解决这个问题?谢谢。

更新:我正在尝试将这段代码添加到构建和运行良好的 Android 项目中的现有 C++ 代码中。当我应用上面链接的更改时,我不仅得到了 fstream 的unresolved inclusion,而且还得到了一堆其他错误。例如,对于现有代码的以下块:

#include <jni.h>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <vector>

我也收到Unresolved inclusion 错误。所以事情变得更糟了。

【问题讨论】:

    标签: android c++ porting invalid-argument


    【解决方案1】:

    尝试将以下行添加到您项目的Application.mk

    APP_STL := gnustl_static
    

    【讨论】:

      猜你喜欢
      • 2018-09-28
      • 2011-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-06
      • 2015-07-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多