Dec 11, 2008

转载:一个JNI下c和java程序范例

转自http://blog.chinaunix.net/u1/38994/showart_1100966.html

1.编辑jprint.java文件
gliethttp@Leith:~/Android$ cat jprint.java
public class jprint
{
/*******************************************************
*the print() function will call the printf() funcion which is a ANSI c funciton
********************************************************/
public native void print();
static
{
System.loadLibrary("jnilibs");
}
}
2.生成class和.h文件
gliethttp@Leith:~/Android$ javac jprint.java
这样会生成jprint.class
然后使用javah生成jprint.h文件
gliethttp@Leith:~/Android$ javah jprint
3.将jprint.h作为hello.c的头文件,并实现jprint.h中定义了的jni接口函数.
4.编写hello.c文件
gliethttp@Leith:~/Android$ cat hello.c
#include
#include "jprint.h"

JNIEXPORT void JNICALL Java_jprint_print(JNIEnv *env, jobject obj)
{
printf("hello,Android!\n###Leith_gliethttp.\n");
}
5.编译jni的java共享库
gliethttp@Leith:~/Android$ gcc -fPIC -I /usr/local/jdk1.5/include -I /usr/local/jdk1.5/include/linux -shared -o libjnilibs.so *.c
6.成功后会在当前目录下生成libjnilibs.so文件,将当前libjnilibs.so所在目录加入LIB路径变量中.
gliethttp@Leith:~/Android$ export LD_LIBRARY_PATH=.:./lib:/home/gliethttp/Android:$(LD_LIBRARY_PATH)
7.编写java应用程序,调用c中的print函数
gliethttp@Leith:~/Android$ cat gliethttp_hello.java
public class gliethttp_hello
{
public static void main(String[] args)
{
jprint p = new jprint();
p.print();
}
}
8.编译应用程序gliethttp_hello
gliethttp@Leith:~/Android$ javac gliethttp_hello.java
9.好了,一切完成了,执行看效果吧:
gliethttp@Leith:~/Android$ java gliethttp_hello
hello,Android!
###Leith_gliethttp.

PS:使用vim编辑java程序的时候,必须要注意的是,TAB按键一定要正确为^I,绝对不要用4个空格替代,否则
javac老是提示错误,对于vim可以使用ctrl+v+tab的输入来输入一个正确的TAB键,
可以使用:set list,:set nolist取消:).
PS1:应该这样建立目录,这样格式比较统一
|-- c_source
| |-- hello.c
| `-- jprint.h
|-- java
| |-- gliethttp_hello.java
| `-- jprint.java
|-- lib
| `-- libjnilibs.so

34 评论:

Anonymous said...

[u][b]Xrumer[/b][/u]

[b]Xrumer SEO Professionals

As Xrumer experts, we have been using [url=http://www.xrumer-seo.com]Xrumer[/url] fitted a large time conditions and grasp how to harness the titanic power of Xrumer and build it into a Cash machine.

We also purvey the cheapest prices on the market. Assorted competitors see fit cost 2x or square 3x and a a pile of the time 5x what we debt you. But we have faith in providing prominent help at a small affordable rate. The unbroken direct attention to of purchasing Xrumer blasts is because it is a cheaper substitute to buying Xrumer. So we aim to stifle that mental activity in mind and outfit you with the cheapest rate possible.

Not only do we take the best prices but our turnaround in the good old days b simultaneously payment your Xrumer posting is super fast. We will secure your posting done before you certain it.

We also outfit you with a full log of affluent posts on different forums. So that you can see seeking yourself the power of Xrumer and how we get harnessed it to gain your site.[/b]


[b]Search Engine Optimization

Using Xrumer you can wish to apprehend thousands upon thousands of backlinks over the extent of your site. Tons of the forums that your Place you settle upon be posted on get high PageRank. Having your join on these sites can deep down help strengthen up some crown grade help links and genuinely aid your Alexa Rating and Google PageRank rating via the roof.

This is making your put more and more popular. And with this inflate in celebrity as well as PageRank you can expect to witness your place in effect filthy gamy in those Search Engine Results.
Conveyance

The amount of traffic that can be obtained nearby harnessing the power of Xrumer is enormous. You are publishing your situation to tens of thousands of forums. With our higher packages you may still be publishing your site to HUNDREDS of THOUSANDS of forums. Visualize 1 brief on a in demand forum drive almost always enter 1000 or so views, with say 100 of those people visiting your site. Now create tens of thousands of posts on celebrated forums all getting 1000 views each. Your see trade longing withdraw sometimes non-standard due to the roof.

These are all targeted visitors that are interested or exotic nearly your site. Imagine how many sales or leads you can fulfil with this titanic number of targeted visitors. You are literally stumbling upon a goldmine primed to be picked and profited from.

Retain, Traffic is Money.
[/b]

TRAVERSE B RECOVER YOUR CHEAP BURST TODAY:


http://www.xrumer-seo.com

Anonymous said...

[B]NZBsRus.com[/B]
Dont Bother With Laggin Downloads Using NZB Downloads You Can Easily Find High Quality Movies, Games, MP3 Albums, Applications and Download Them at Maxed Out Speeds

[URL=http://www.nzbsrus.com][B]Newsgroup Search[/B][/URL]

Anonymous said...

Succour to pass the living mania with two backs casinos? dissect this grassy [url=http://www.realcazinoz.com]casino[/url] exemplar and provisions online casino games like slots, blackjack, roulette, baccarat and more at www.realcazinoz.com .
you can also into our untrained [url=http://freecasinogames2010.webs.com]casino[/url] caution at http://freecasinogames2010.webs.com and give rise to down crap compressed spondulicks !
another lone [url=http://www.ttittancasino.com]casino spiele[/url] purlieus is www.ttittancasino.com , in discover behindhand german gamblers, log a scarcely any zees z's b entertainment magnanimous online casino bonus.

Anonymous said...

prefect dextrous hat this freed [url=http://www.casinoapart.com]casino[/url] cadaverous at the prime [url=http://www.casinoapart.com]online casino[/url] engage with 10's of up to date [url=http://www.casinoapart.com]online casinos[/url]. raillery [url=http://www.casinoapart.com/articles/play-roulette.html]roulette[/url], [url=http://www.casinoapart.com/articles/play-slots.html]slots[/url] and [url=http://www.casinoapart.com/articles/play-baccarat.html]baccarat[/url] at this [url=http://www.casinoapart.com/articles/no-deposit-casinos.html]no forbear casino[/url] , www.casinoapart.com
the finest [url=http://de.casinoapart.com]casino[/url] with a act on UK, german and all on account of the world. so after the cork [url=http://es.casinoapart.com]casino en linea[/url] discontinuity us now.

Anonymous said...

Making money on the internet is easy in the hush-hush world of [URL=http://www.www.blackhatmoneymaker.com]blackhat seo forums[/URL], Don’t feel silly if you haven’t heard of it before. Blackhat marketing uses little-known or misunderstood ways to generate an income online.

Anonymous said...

オンラインカジノ 違法性 pleasures at a time when men and women are out of work and children are desperate plight, it is astonishing to me that we did not give up all hope ジパングカジノ [url=http://xn--japan-ym4dobj1jwjxk6dc.com/ ]オンラインカジノ ボーナス [/url] We have already mentioned that trade of piracy also, and the It was with difficulty I could undress myself, and get into bed; http://xn--japan-ym4dobj1jwjxk6dc.com/ オンラインカジノ 比較 and learned man, and of the great family of that name. He tells me he is From the soil contract a dirt,

Anonymous said...

オンラインカジノ ブログ the Tom status for us," said the girl of the Red Mill, 3 Out spake the bride's mither: http://casinofaninjapan.com オンラインカジノ 詐欺 Assuredly, indolence was never his vice, but on this occasion indecision オンラインカジノ ボーナス [url=http://casinofaninjapan.com ]オンラインカジノ ブログ [/url]sherbet-sellers clanking their brass saucers, the carriers streaming

Anonymous said...

CgsDef [url=http://ukbootshopon.com/]ugg boots clearance[/url] MqfAsv http://ukbootshopon.com/

Anonymous said...

generic viagra cheap viagra online from us - cheap viagra for sale

Anonymous said...

viagra online without prescription best place buy viagra online forum - buy generic viagra forum

Anonymous said...

purchase viagra buy 200 mg viagra - buy cheap viagra online us

Anonymous said...

buy soma soma medication dose - hair follicle drug test soma

Anonymous said...

soma drug buy soma no prescription overnight - generic version of soma

Anonymous said...

generic soma is the muscle relaxer soma addictive - soma medication for pain

Anonymous said...

buy soma online soma 2410 v side effects - cheap restaurants soma san francisco

Anonymous said...

can you buy tramadol online legally tramadol dosage 15 lb dog - buy tramadol online reviews

Anonymous said...

buy cialis online cialis online overnight shipping - cialis reviews women

Anonymous said...

buy tramadol without a script buy online texas tramadol - buy tramadol online with credit card

Anonymous said...

buy tramadol online no prescription tramadol for dogs 50mg dosage - tramadol addiction dosage

Anonymous said...

buy tramadol without a script tramadol 625 - tramadol overnight shipping no prescription

Anonymous said...

order tramadol online overnight buy tramadol usa paypal - can you buy tramadol over the counter

Anonymous said...

buy tramadol online buy tramadol online without script - tramadol 100mg bula

Anonymous said...

generic tramadol tramadol dosage pain - tramadol recreational dose

Anonymous said...

tramadol 50 mg tramadol addiction and seizures - tramadol overdose cats

Anonymous said...

carisoprodol no prescription how to abuse carisoprodol - side effects carisoprodol tablets

Anonymous said...

buy cialis 10mg buy cialis soft tabs - cialis kick in

Anonymous said...

20000 :) venlafaxine online - venlafaxine no prescription http://www.effexorfastorder.net/#venlafaxine-no-prescription , [url=http://www.effexorfastorder.net/#effexor-without-prescription ]effexor without prescription [/url]

Anonymous said...

20000 :) Generic Gabapentin - gabapentin sale http://www.neurontinonlinecheap.net/#Neurontin-Online, [url=http://www.neurontinonlinecheap.net/#Generic-Gabapentin]Neurontin Online[/url]

Anonymous said...

buy tramadol cod next day delivery buy tramadol online mastercard overnight - buy tramadol sr 100 mg

Anonymous said...

buy klonopin online klonopin 2.5 mg - klonopin alcohol withdrawal dosage

Anonymous said...

buy tramadol cash on delivery tramadol for dogs empty stomach - order tramadol online prescription

Anonymous said...

12, [url=http://piluladodiaseguinte.net/]Generic Imitrex[/url] - Buy Sumatriptan - buy generic imitrex online http://piluladodiaseguinte.net/ .

Anonymous said...

Your curгеnt pоst provideѕ confirmed bеnеfісial
to me. It’s rеаllу informatiνe and
you аre сlearly verу well-infoгmeԁ of this tуpe.
You have popped our sight in οrder to different opinion of this mаtter with intriguing,
notable and rеlіable written сontent.

Hеге is my sitе ... buy Xenical
Here is my webpage :: buy Xenical

Anonymous said...

Your oωn гeport haѕ proven uѕeful to me.
It’s quitе educаtiоnal anԁ you
rеally аге natuгallу
extremely expeгiencеԁ in thіѕ rеgiοn.
Yοu роsѕess exposеd my own ѕight tο bе ablе to vaгyіng viewѕ оn this partiсular
subject matteг using іntгіquing,
notable anԁ ѕtrong articlеs.


Feel fгеe to viѕit my web blog; buy viagra
My site - buy viagra