如何使用Microsoft Visual C ++编写代码以调用JNI [英] How to write code to call JNI using microsoft visual c++

查看:135
本文介绍了如何使用Microsoft Visual C ++编写代码以调用JNI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在microsoft visual c++ 2010 Express中编写C代码?我无法做到.我在写一些C代码,但编译时出错.

How do I write C code in microsoft visual c++ 2010 Express? I am unable to do it. I was writing some C code but it is compiled with errors.

请提出一些建议?

我写了这段代码:

#include "jni.h"
#include "stdio.h"
#include "HelloWorld.h"

JNIEXPORT void JNICALL
Java_HelloWorld_print(JNIEnv *env, jobject obj) {
    printf("This is a JNI tester");
    return;
}

我遇到以下错误:

helloworld.cpp(1):致命错误C1083:无法打开包含文件:'jni.h'没有此类文件或目录

helloworld.cpp(1): fatal error C1083: Cannot open include file: 'jni.h' No such file or directory

推荐答案

我从未完成过JNI特定的代码,但是您的错误表明它找不到文件"jni.h".您可能需要将该文件放入解决方案文件中,或者进入项目选项,然后在C/C ++选项中指定JNI头文件所在的文件夹.我建议使用后一种方法,即在项目的包含选项中添加文件夹.

I've never done JNI specific code but your error says it cannot find the file "jni.h". You probably need to drop that file inside your solution file or go in project options and in C/C++ options specify the folder where JNI header files are located. I'd recommend the later approach i.e. add the folder in include options of project.

具体步骤为:

  1. 转到项目属性

  1. go to your project properties

在树中导航到配置属性-> C/C ++",然后查看第一个条目其他包含目录"

navigate in the tree to "Configuration Properties->C/C++" then look at the first entry "Additional Include Directories"

在其中输入路径:"*JDKVersionPath*\include";"*JDKVersionPath*\include\win32"

in there enter the path: "*JDKVersionPath*\include";"*JDKVersionPath*\include\win32"

您的JDK安装所在的位置是C:\Program Files\Java\jdk1.6.0\,而JDKVersionPath就是其中的位置(路径版本可能会因所安装的版本而异.

Where JDKVersionPath is where your JDK install resides like C:\Program Files\Java\jdk1.6.0\ (the path version can especially vary depending on the version you have installed.

这篇关于如何使用Microsoft Visual C ++编写代码以调用JNI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆