Note that there are some explanatory texts on larger screens.

plurals
  1. PODebugging JNI Code with Xcode 4 / OS X 10.6
    primarykey
    data
    text
    <p>I've been tearing my hair out trying to figure out something that's braindead in Windows / Visual Studio. I have a JNI library under OS X 10.6 that I would like to invoke with the Java executable and debug under Xcode: stepping through code, examining variables in my JNI library, setting breakpoints, etc.</p> <p>Here is a working JNI example which compiles and runs fine from the command line. If someone could tell me how to set this up in Xcode, I'd be eternally grateful. Ideally, I'd like step-by-step instructions starting from scratch in Xcode and cutting and pasting from the code below as appropriate, resulting in something that is debuggable under Xcode 4 and allowing me to set breakpoints in the JNI code, examine variables, see stacktraces, etc.</p> <p>As a token of gratitude, I'll send $20 to the first person that gives me such instructions I can reproduce on my end if you give me a Paypal address.</p> <p>Thanks in advance!</p> <p><strong>HelloWorld.java</strong></p> <pre class="lang-java prettyprint-override"><code>class HelloWorld { public native String displayHelloWorld(); static { System.loadLibrary("HelloWorldImp"); } public static void main(String[] args) { System.out.println("--&gt; "+new HelloWorld().displayHelloWorld()); } } </code></pre> <p><strong>HelloWorldImp.mm</strong></p> <pre class="lang-cpp prettyprint-override"><code>#include &lt;stdio.h&gt; #include &lt;jni.h&gt; #include &lt;string&gt; #import &lt;Foundation/Foundation.h&gt; #ifdef __cplusplus extern "C" { #endif JNIEXPORT jstring JNICALL Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSString* name = @"Yo Cocoa"; std::string s = [name UTF8String]; jstring ret = env-&gt;NewStringUTF(s.c_str()); [pool drain]; return ret; } #ifdef __cplusplus } #endif </code></pre> <p><strong>buildjni.sh</strong></p> <pre class="lang-bsh prettyprint-override"><code>gcc -bundle -I/System/Library/Frameworks/JavaVM.framework/Headers -lstdc++ -o libHelloWorldImp.jnilib -framework Foundation HelloWorldImp.mm </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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