簡體   English   中英

JNI:沒有制定目標的規則

[英]JNI: No rule to make target issue

我只是在Eclipse中學習JNI,並已在Ubuntu中關注了 JNI教程的Eclipse部分。 我設法通過使用以下文件夾結構來使其工作:

.
└── HelloJNI
    ├── bin
    │   └── HelloJNI.class
    ├── jni
    │   ├── HelloJNI.c
    │   ├── HelloJNI.h
    │   ├── HelloJNI.o
    │   ├── libhello.so
    │   └── makefile
    └── src
        ├── HelloJNI.class
        └── HelloJNI.java

我在此項目中的makefile如下所示:

# Define a variable for classpath
CLASS_PATH = ../bin

# Define a virtual path for .class in the bin directory
vpath %.class $(CLASS_PATH)

all : libhello.so

# $@ matches the target, $< matches the first dependancy
libhello.so : HelloJNI.o
    gcc -shared -fpic -o $@ $<

# $@ matches the target, $< matches the first dependancy
HelloJNI.o : HelloJNI.c HelloJNI.h
    gcc -fpic -I"/usr/lib/jvm/java-6-openjdk-amd64/include" -I"/usr/lib/jvm/java-6-openjdk-amd64/include/linux" -c $< -o $@

# $* matches the target filename without the extension
HelloJNI.h : HelloJNI.class
javah -classpath $(CLASS_PATH) $*

clean :
    rm HelloJNI.h HelloJNI.o libhello.so

現在,我想在我的Android Libgdx項目中復制它。 我的核心項目的文件夾結構如下所示:

.
├── bin
│   ├── com
│   │   └── test
│   │       └── mytestgame
│   │           ├── TestGame.class
│   │           └── TextGenerator.class
│   └── TestGame.gwt.xml
├── jni
│   └── makefile
├── libs
│   ├── gdx.jar
│   └── gdx-sources.jar
└── src
    ├── com
    │   └── test
    │       └── mytestgame
    │           ├── TestGame.java
    │           └── TextGenerator.java
    └── TestGame.gwt.xml

我在該項目中的makefile定義為:

# Define a variable for classpath
CLASS_PATH = ../bin

# Define a virtual path for .class in the bin directory
vpath %.class $(CLASS_PATH)

all : libTextGenerator.so

# $@ matches the target, $< matches the first dependancy
libTextGenerator.so : TextGenerator.o
        gcc -shared -fpic -o $@ $<

# $@ matches the target, $< matches the first dependancy
TextGenerator.o : TextGenerator.cpp TextGenerator.h
        gcc -fpic -I"/usr/lib/jvm/java-6-openjdk-amd64/include" -I"/usr/lib/jvm/java-6-    openjdk-amd64/include/linux" -c $< -o $@

# $* matches the target filename without the extension
TextGenerator.h : TextGenerator.class
        javah -classpath $(CLASS_PATH) $*

clean :
        rm TextGenerator.h TextGenerator.o libTextGenerator.so

TextGenerator類僅作為生成半隨機文本的TextGenerator工作,以測試我是否可以在Java中使用C ++中的String。 這個類看起來像這樣:

package com.test.mytestgame;

public class TextGenerator {
    static{
            System.load("TextGenerator"); // Filename libTextGenerator.so
    }

    /**Empty constructor.*/
    public TextGenerator(){
    }

    /**Returns a semi-not-so-random-text*/
    public native String generateText();    
}

現在的問題是,當我嘗試運行makefile的TextGenerator.h部分時,出現以下錯誤:

**** Build of configuration Default for project my-fluids-game ****

make TextGenerator.h 
make: *** No rule to make target `TextGenerator.class', needed by `TextGenerator.h'.  Stop.

**** Build Finished ****

我嘗試將CLASS_PATH變量更改為../bin/com/test/mytestgame但這只會產生其他錯誤。 據我了解,在使用-classpath標志時可以使用../bin。

誰能告訴我我哪里錯了? 我想這是一個相對較小的細節,但是目前我對此的了解有限。

make不知道有關類路徑。

規則應該是

TextGenerator.h : ../bin/com/test/mytestgame/TextGenerator.class
    javah -classpath $(CLASS_PATH) $(<F)

但是我真的不知道您將如何使用javah生成的包含文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM