首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

Java怎么调用C/C++(JNI)

2012-12-25 
Java如何调用C/C++(JNI)1.?program?Java?source?file?loading?Native?method???b?:?use?javah?-stubs?Nati

Java如何调用C/C++(JNI)

1.?program?Java?source?file?loading?Native?method?

?

?

b?:?use?javah?-stubs?NativeDemo?to?produce?NativeDemo.c?which?seems?as:

?

?

5.?link?NativeDemo.c?and?test.c?to?produce?NativeDemo.dll?
Use?VC++5.0?tools?:Cl.exe?
Cl?/GD?NativeDemo.c?test.c?/LD?
then?we?get?NativeDemo.dll?


NativeDemo.c?
test.c?
Generating?Code...?

/out:NativeDemo.dll?
/dll?
/implib:NativeDemo.lib?
NativeDemo.obj?
test.obj?
Creating?library?NativeDemo.lib?and?object?NativeDemo.ex?
Press?any?key?to?continue

?

6.Run?

java?NativeDemo?

we?get?the?such?result:?

?

D:\vj11user\native>java NativeDemo hello:! this is in the native method! this is ob.i:10 this is ob.j:20 D:\vj11user\native> 
?


NOTE:?
Do?not?forget?this:?
c:>?set?INCLUDE=d:\java\include;d:\java\win32;%INCLUDE%?
C:>set?LIB?=d:\java\lib;%LIB%?
where?d:\java?is?the?directory?of?your?jdk?

new?version?jdk1.2.1?:?

With?new?jdk1.2.1?:?

1.javac?NativeDemo.java?

2.?javah?NativeDemo?to?produce?head?file?(You?need?not?to?javah?-stubs?NativeDemo?to?produce?NativeDemo.c?file),?

You?don`t?need?the?c?file.?Just?the?NativeDemo.h?is?sufficient!?

3.Use?VC++?produce?a?window?dll?project?and?add?the?NativeDemo.h?to?it.?

then?implement?the?function.?All?is?OK!?
NOTE:?the?data?type?conversion?between?java?and?c++.See?jni.h?for?more?information.?

?

?

?

?

?

热点排行