0

I'm writing an Adroid app with some C++ code behind the UI using Eclipse + NDK (r8d). I have some code that I thought was fool proof but the compiler just gives me weird errors like "Invalid arguments" without specifics. Here is what my C++ code looks like:

#include <jni.h>
#include <string>
using namespace std;
#include "../../Evaluator.Engine/Evaluator.Engine.h"

Evaluator evaluator;

extern "C" {
    JNIEXPORT jstring JNICALL Java_haskellevaluator_android_MainActivity_evaluateNative(JNIEnv *env, jobject, jstring jInput)
    {
        ...
        string sInput(L"Hello world");
        string sResult = evaluator.evaluate(sInput);
        jstring jResult = env->NewStringUTF(sResult.data());
        return jResult;
    }
}

Evaluator.Engine.h is nothing fancy, but just a declaration of the class Evaluator.

#include <string>
using namespace std;

class Evaluator
{
public:
    string evaluate(string input);
};

However, the compiler complains:

Invalid arguments '
Candidates are:
? evaluate(?)
'

as if string is not defined. But if I put a copy of the header file under the same folder, the error goes away. This is a Windows box. I have tried using \ and escaped \\ as path separators and it didn't work.

Does this sound like a NDK (or whatever the preprocessor it uses) bug? I don't want to move the header file because it'll be shared by other projects. I also hate to keep 2 copies of the same file.

Any ideas? Thanks.

delingren
  • 13
  • 4
  • Where's the rest of the compiler complaint? You didn't paste the full error there. Also, you generally don't pass around strings in C++- pass a const string& instead, to prevent excess object creation and copy constructor calling – Gabe Sechan Jun 28 '14 at 01:13
  • I managed to reduce the errors to just this one. – delingren Jun 28 '14 at 01:18
  • Where is sInput coming from? jInput is passed in, the best I can guess from the partial error message you passed in is that sInput isn't the right type. – Gabe Sechan Jun 28 '14 at 01:23
  • It's declared as string. I have further reduced the code to so that Evaluator class has nothing but a function "void foo()", and it's referenced in the JNI function. It's still not working. The error says "Method foo could not be resolved". Again, if I copy the header file under the same folder, it compiles fine. At this point, I'm pretty sure it's a preprocessor bug. – delingren Jun 28 '14 at 02:17
  • Stupid question, but are you sure your path is correct? Have you tried adding that directory as part of the include path for your build in your makefile? – Gabe Sechan Jun 28 '14 at 02:25
  • Yes I'm sure. That was the first thing I double checked. I know it's the end of a long week :). Actually if the path is incorrect, I get a different error. How do I add it to the include path? I assume I can set it in Android.mk or Application.mk? – delingren Jun 28 '14 at 05:01
  • It is very often that **ndk-build** succeeds, but Eclipse *indexer* fails to find the include files. Is *[this](http://stackoverflow.com/questions/23155676/android-ndk-build-method-could-not-be-resolved)* the case? – Alex Cohn Jun 28 '14 at 07:07

1 Answers1

1

Sorry I don't have windows OS, but I've tried you code on a MacOS, but it doesn't work because of:

string sInput(L"Hello world");

Saying that wchar_t cannot be put on std::string. Is it possible to be the same problem ?

smaryus
  • 349
  • 3
  • 12