• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
How to determine import statements to use for a Cocoa class for a JNI method?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to determine import statements to use for a Cocoa class for a JNI method?


  • Subject: How to determine import statements to use for a Cocoa class for a JNI method?
  • From: Rob Ross <email@hidden>
  • Date: Mon, 11 Sep 2006 16:21:13 -0700

I am starting to work on writing some Cocoa code that will be executed as a native method via JNI from a Java application.

I'm starting small, trying to create an NSString without doing anything else to it. My method works but I get a console error message telling me there's no current NSAutoReleasePool.

Ok, so I know how to do this in Cocoa and so I add the auto release pool code to my native method:

#include "NSStringProcessing.h"
#import <Cocoa/Cocoa.h>
#import <JavaVM/jawt_md.h>

JNIEXPORT jstring JNICALL Java_NSStringProcessing_reverseString (JNIEnv *env, jobject obj, jstring my_jstring)
{
NSAutoReleasePool *pool = [[NSAutoReleasePool alloc] init];


    printf("In native method reverseString");
    NSString *str = [NSString stringWithCString:"Hi there mom"];

    [pool release];

    return my_jstring; //just return the string that was passed in
}

I'm including the Cocoa.h and jawt_md.h only because that's what was included in the sample Xcode project for the JSheets project, which I found here: http://developer.apple.com/samplecode/JSheets/index.html

after reading this technote: http://developer.apple.com/technotes/ tn2005/tn2147.html

(I know that if I omit the include for Cocoa.h then the NSString token causes a compiler error; I have no idea what the jawt_md.h is for. )

Then I try to compile from the command line:

gcc -c -I/System/Library/Frameworks/JavaVM.framework/Headers -I/ System/Library/Frameworks/Cocoa.framework/Headers NSStringProcessing.m

and I get this compiler error:

NSStringProcessing.m: In function 'Java_NSStringProcessing_reverseString':
NSStringProcessing.m:7: error: 'NSAutoReleasePool' undeclared (first use in this function)
NSStringProcessing.m:7: error: (Each undeclared identifier is reported only once
NSStringProcessing.m:7: error: for each function it appears in.)
NSStringProcessing.m:7: error: 'pool' undeclared (first use in this function)


This leads me to conclude I that haven't included the right header file that contains the declaration for NSAutoReleasePool.

So how do I find the right ".h" file to include? And when I later link, with :

gcc -dynamiclib -o libNSStringProcessing.jnilib NSStringProcessing.o - framework JavaVM -framework Cocoa


how do I know what other -framework to include based on the headers I previously included?


Thanks,

Rob Ross, Lead Software Engineer
E! Networks
email@hidden
---------------------------------------------------
"Beware of he who would deny you access to information, for in his heart he dreams himself your master." -- Commissioner Pravin Lal



_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: How to determine import statements to use for a Cocoa class for a JNI method?
      • From: Ricky Sharp <email@hidden>
    • Re: How to determine import statements to use for a Cocoa class for a JNI method?
      • From: "Shawn Erickson" <email@hidden>
  • Prev by Date: Re: NSChineseCalendar
  • Next by Date: Re: How to determine import statements to use for a Cocoa class for a JNI method?
  • Previous by thread: Re: NSChineseCalendar
  • Next by thread: Re: How to determine import statements to use for a Cocoa class for a JNI method?
  • Index(es):
    • Date
    • Thread