Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid - C++ compile errors in cygwin/android-ndk
    text
    copied!<p>Ive created a simple app to help me learn the ndk, jni, and get my c++ skills back up to par. However Im kind of stuck because Im getting some compile errors when I run ndk-build on my project from the cygwin command line. Its been a while since Ive used c++ to any extent so I know that my syntax is probably way off so if some one could help me clean this up or explain how I could do so then that would be awesome.....so heres my c++ code:</p> <p>EDIT: latest code</p> <pre><code>#include &lt;iostream&gt; #include &lt;Eigen/Dense&gt; #include &lt;math.h&gt; #include &lt;jni.h&gt; using namespace Eigen; Vector3f vec; Vector3f vec2; Vector3f vecRtrn; void vecLoad(float x, float y, float z, float x2, float y2, float z2){ vec(0) = x; vec(1) = y; vec(2) = z; vec2(0) = x2; vec2(1) = y2; vec2(2) = z2; } void vecAdd(Vector3f vecA, Vector3f vecB){ vecRtrn = vecA+vecB; } extern "C" { JNIEXPORT jfloatArray JNICALL Java_jnimath_act_JnimathActivity_test (JNIEnv *env, jobject obj, jfloatArray fltarray1, jfloatArray fltarray2){ float array1[3]; jfloatArray flt1 = fltarray1; jfloatArray flt2 = fltarray2; //flt1 = env-&gt;GetFloatArrayElements( fltarray1,0); //flt2 = env-&gt;GetFloatArrayElements( fltarray2,0); vecLoad(flt1[0], flt1[1], flt1[2], flt2[0], flt2[1], flt2[2]); vecAdd(vec, vec2); array1[0] = vecRtrn[0]; array1[1] = vecRtrn[1]; array1[2] = vecRtrn[2]; return array1; }; } </code></pre> <p>Now Im pretty sure Im not using the correct way to return the array back to java through jni but thats a separate problem......but please feel free to comment on that as well ;)</p> <p>Heres an updated list of the last couple of build errors I have.....its definitely a lot shorter than the original list :) </p> <pre><code>$ /cygdrive/c/android-ndk-r7/ndk-build Compile++ thumb : test &lt;= test.cpp jni/test.cpp: In function '_jfloatArray* Java_jnimath_act_JnimathActivity_test(JNIEnv*, _jobject*, _jfloatArray*, _jfloatArray*)': jni/test.cpp:42: error: cannot convert '_jfloatArray' to 'float' for argument '1' to 'void vecLoad(float, float, float, float, float, float)' jni/test.cpp:49: error: cannot convert 'float*' to '_jfloatArray*' in return make: *** [obj/local/armeabi/objs/test/test.o] Error 1 </code></pre> <p>EDIT: heres my java code......</p> <pre><code>package jnimath.act; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; public class JnimathActivity extends Activity { /** Called when the activity is first created. */ public EditText x; public EditText y; public EditText z; public EditText x2; public EditText y2; public EditText z2; public float[] vecArray; public TextView textView1; public Button run; float[] array3 = new float[3]; float[] array1 = new float[3]; float[] array2 = new float[3]; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); x = (EditText)findViewById(R.id.x); y = (EditText)findViewById(R.id.y); z = (EditText)findViewById(R.id.z); x2 = (EditText)findViewById(R.id.x); y2 = (EditText)findViewById(R.id.y); z2 = (EditText)findViewById(R.id.z); textView1 = (TextView)findViewById(R.id.textView1); run = (Button)findViewById(R.id.run); run.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { array1[0] = Float.parseFloat(x.getText().toString()); array1[1] = Float.parseFloat(y.getText().toString()); array1[2] = Float.parseFloat(z.getText().toString()); array2[0] = Float.parseFloat(x2.getText().toString()); array2[1] = Float.parseFloat(y2.getText().toString()); array2[2] = Float.parseFloat(z2.getText().toString()); array3 = test(array1, array2); String text = array3[0]+" "+array3[1]+" "+array3[2]; textView1.setText(text); } }); } public native float[] test(float[] array1, float[] array2); static { System.loadLibrary("test"); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload