尝试编译基本JNI测试代码时VS2010出错

时间:2015-03-04 18:14:25

标签: java c++ visual-studio-2010 java-native-interface

我正在尝试编译一个基本的JNI测试以准备DLL(带有头文件和lib文件)我希望在接下来的几天内收到我需要为其创建JNI接口。

我试过将它指向JNI.lib的x64 / x86库。我试过根本没把它指向lib。我已经尝试将它指向包含目录的x64 / x86版本,但它总是与下面的错误相同。

Visual Studio给出了以下错误,我不明白为什么:

1>------ Build started: Project: CLibHelloWorld, Configuration: Debug Win32 ------
1>Build started 04/03/2015 19:04:09.
1>InitializeBuildStatus:
1>  Creating "Debug\CLibHelloWorld.unsuccessfulbuild" because "AlwaysCreate" was specified.
1>ClCompile:
1>  CLibHelloWorld.c
1>Link:
1>     Creating library F:\Work\04-Companies\DigitalARCSystems\KlearKapture\CameraInterface\test\test-jni\Debug\CLibHelloWorld.lib and object F:\Work\04-Companies\DigitalARCSystems\KlearKapture\CameraInterface\test\test-jni\Debug\CLibHelloWorld.exp
1>  test-jni.vcxproj -> F:\Work\04-Companies\DigitalARCSystems\KlearKapture\CameraInterface\test\test-jni\Debug\CLibHelloWorld.dll
1>FinalizeBuildStatus:
1>  Deleting file "Debug\CLibHelloWorld.unsuccessfulbuild".
1>  Touching "Debug\CLibHelloWorld.lastbuildstate".
1>
1>Build succeeded.
1>
1>Time Elapsed 00:00:00.43
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

HelloWorld.java(使用javac HelloWorld.java编译):

class HelloWorld {
    public native void print();  //native method
    static   //static initializer code
    {
        System.loadLibrary("CLibHelloWorld");
    } 

    public static void main(String[] args)
    {
        HelloWorld hw = new HelloWorld();
        hw.print();
    }
}

HelloWorld.h(由javah -jni HelloWorld生成):

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class HelloWorld */

#ifndef _Included_HelloWorld
#define _Included_HelloWorld
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     HelloWorld
 * Method:    print
 * Signature: ()V
 */
JNIEXPORT void JNICALL Java_HelloWorld_print
  (JNIEnv *, jobject);

#ifdef __cplusplus
}
#endif
#endif

CLibHelloWorld.c:

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

JNIEXPORT void JNICALL Java_HelloWorld_print(JNIEnv *env, jobject obj)
{
    printf("Hello world\n");
    return;
}

1 个答案:

答案 0 :(得分:1)

将评论转换为答案,因为显然它有助于解决问题。

调查MSBuild问题的一种方法是查看详细日志。从VS命令提示符,cd到项目目录,然后执行命令msbuild MyProject.vcxproj /v:d。这将建立详细的详细程度。在输出中搜索链接器命令,您应该看到类似

的内容
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\link.exe /OUT:"c:\my_output_path\myfile.dll" ...

链接器的/ OUT选项就是你所追求的。如果根本没有调用链接器,则有一些设置不需要为项目生成二进制文件。