Note that there are some explanatory texts on larger screens.

plurals
  1. POerror: unknown type name 'class' NDK CDT JNI
    text
    copied!<p>I'm using Eclipse ADT with: CDT. Along with NDK interfacing with JNI, to c/c++, compiling c/c++ with Cygwin through Eclipse. Everything should be running the latest versions as this was just setup over the last two weeks. </p> <p>When Building I get the following.</p> <pre><code>jni/testSocketClass.hpp:33:1: error: unknown type name 'class' jni/testSocketClass.hpp:33:17: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token jni/ndkfoo.c:13:1: error: unknown type name 'mYNewClass' </code></pre> <p>JNI C file</p> <pre><code>#include &lt;string.h&gt; #include &lt;jni.h&gt; #include "testSocketClassWrapper.hpp" void *m_GBLpmyCSocket; ndkfoo.c jstring Java_com_example_hydrobedcontrol1_MainActivity_inintNativeClass(JNIEnv * env, jobject object){ m_GBLpmyCSocket = MyClass_create(); MyClass_sendCommandToSerialDevice(m_GBLpmyCSocket, 0, 0, 0); return (*env)-&gt;NewStringUTF(env, "started"); } </code></pre> <p>Class Wrapper .hpp</p> <pre><code> //file testSocketClassWrapper.hpp #ifndef _MY_SOCKETCLASS_WRAPPER_H #define _MY_SOCKETCLASS_WRAPPER_H #include"testSocketClass.hpp"//&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;Wrong inclusion #ifdef __cplusplus extern "C" void* MyClass_create() { return new mYNewClass; } extern "C" void MyClass_release(void* myclass) { delete static_cast&lt;mYNewClass*&gt;(myclass); } extern "C" void MyClass_sendCommandToSerialDevice(void* myclass, int cmd, int params, int id) { static_cast&lt;mYNewClass*&gt;(myclass)-&gt;sendCommandToSerialDevice(cmd,params,id); } #endif #endif /* _MY_SOCKETCLASS_WRAPPER_H_INCLUDED */ </code></pre> <p>Class wrapper .cpp</p> <pre><code>//file testSocketClassWrapper.cpp #include "testSocketClassWrapper.hpp" </code></pre> <p>Class .h</p> <pre><code>// file testSocketClass.hpp class mYNewClass{///////////////////////ERROR HERE//////////////////////////////// //public: void sendCommandToSerialDevice(int Command, int Parameters, int DeviceID); //int sockfd; }; </code></pre> <p>Class .cpp</p> <pre><code>// file testSocketClass.cpp #include "testSocketClass.hpp" void mYNewClass::sendCommandToSerialDevice(int Command, int Parameters, int DeviceID){ char testc[100]; sprintf(testc, "%d, %d, %d", Command, Parameters, DeviceID); } </code></pre> <p>I've read countless questions on this topic and have had quite a few issues getting this far with Eclipse configurations too. But from what I've pulled together from other questions on this topic, I have hit a wall and do not know how to proceed at this point. Suggestions?</p> <p><strong>EDIT BELOW - ANSWER</strong></p> <p>After review with a colleague(sometimes a second pair of eyes helps bring things out), we located my error. See the line labeled improper inclusion in the Class wrapper .hpp. That header should be relocated as follows in the Class wrapper .cpp NOTE: the functions where also moved to the .cpp and the .hpp is now empty.</p> <pre><code>//file testSocketClassWrapper.cpp #include "testSocketClassWrapper.hpp" #include "testSocketClass.hpp" extern "C" void* MyClass_create() { return new mYNewClass; } extern "C" void MyClass_release(void* myclass) { delete static_cast&lt;mYNewClass*&gt;(myclass); } extern "C" void MyClass_sendCommandToSerialDevice(void* myclass, int cmd, int params, int id) { static_cast&lt;mYNewClass*&gt;(myclass)-&gt;sendCommandToSerialDevice(cmd,params,id); } </code></pre> <p>Also for completeness as this has been no walk in the park, are the MK files.</p> <pre><code>Android.mk LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) # Here we give our module name and source file(s) LOCAL_MODULE := ndkfoo LOCAL_SRC_FILES := ndkfoo.c testSocketClassWrapper.cpp testSocketClass.cpp include $(BUILD_SHARED_LIBRARY) Application.mk APP_STL:=stlport_static </code></pre> <p>Thank you for the prompt reply krsteeve. And yet another way to do this. Will keep it in mind.</p>
 

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