Ask Your Question

Invalid arguments for standard function calls

asked 2013-02-11 13:12:07 -0500

seismic gravatar image

updated 2013-04-11 01:43:43 -0500

Andrey Pavlenko gravatar image

*Update: I need to mention that this error only occurs when I open the cpp file. When I close the file and close and open the project, the errors disappear (till I open the file again)*

I want to reuse my native c++ files in a android project. When I paste the files into the jni folder the compiler gives me invalid argument errors for functions like substr or fwrite.

The example:

#include <string>
#include <vector>
using namespace std;
using namespace cv;
std::string str="We think in generalities, but we live in details.";   
std::string str2 = str.substr (12,12);   // "generalities"

image description does the compiler quit with:

Invalid arguments ' Candidates are: std::basic_string<char,std::char_traits<char>,std::allocator<char>> 
 substr(?, ?) '

I obviously missed something general! I'm using OpenCV for Android and C/C++ Dev. Tools 8.0 for Eclipse.


APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi-v7a
APP_PLATFORM := android-8

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
include ../../sdk/native/jni/
LOCAL_MODULE    := native_sample
LOCAL_SRC_FILES := jni_part.cpp
LOCAL_LDLIBS +=  -llog -ldl

image description

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2013-02-12 23:37:05 -0500

It looks like you forgot to add STL support to your project. You need to add include paths to your C project in Eclipse and define STL type in You can use any OpenCV Sample with native code as reference. There is jni/ file and valid Eclipse CDT project config there. See Tutorial-3 and Tuturial-4 if you use OpenCV 2.4.2 or 2.4.3.x and Tutorial-2 if you use 2.4.4b.

edit flag offensive delete link more


It even happens when I post the code into the tutorial 4's jni folder (see Without the substr. function call, the tutorial compiles and runs just finde. STL and CDT Settings should be ok, I guess. But I just saw that I'm using old 8.0.3 version of cdt. I updated to 8.1.1 now. But this is also not the reason.

seismic gravatar imageseismic ( 2013-02-14 12:06:53 -0500 )edit

I'm desperate now, I don't get this error fixed and really need a solution. I installed everything on Mac, migrated to ndk8e, opencv and cdt 8.1.2 and it doesn't work. Has it anything to do with my Toolchain settings (No Toolchain, GnuBuilder)? Do you get errors when you copy these two lines of code into the appropriate tutorial project? std::string str="We think in generalities, but we live in details."; std::string str2 = str.substr (12,12);

seismic gravatar imageseismic ( 2013-04-03 09:49:37 -0500 )edit

This looks like a bug(s) of CDT editor/syntax parser, so you just need to find a way to disable this check in Eclipse.

Andrey Pavlenko gravatar imageAndrey Pavlenko ( 2013-04-04 03:19:24 -0500 )edit

Thanks! I disabled the syntax check in eclipse. Now I don't have syntax check for most errors but at least I can compile now.

seismic gravatar imageseismic ( 2013-04-10 09:29:42 -0500 )edit

Question Tools


Asked: 2013-02-11 13:12:07 -0500

Seen: 2,916 times

Last updated: Apr 11 '13