Eclipse:“ make:***没有规则将目标设置为all。停止。”

时间:2019-05-09 17:21:02

标签: java c eclipse makefile

我正在Eclipse中将本教程用于JNI:

https://www3.ntu.edu.sg/home/ehchua/programming/java/JavaNativeInterface.html#zz-2.6

(我仅使用“ 2.6 JNI in Eclipse ”部分)。

直到本教程的这一部分为止:

  

通过右键单击makefile来运行目标“所有”的makefile⇒生成>目标⇒构建⇒选择目标“ all”⇒构建

一切似乎都运行良好(意味着-结果与教程中的结果相同,并且“问题”标签中没有警告或错误)。

但是当我做这部分时,我注意到那行:

  

javah -classpath ../bin HelloJNI

在控制台中打印时丢失。

然后,我继续本教程的下一步-“ 步骤5:运行Java JNI程序”。

尽管它确实打印到控制台“ Hello World!”,但我注意到“问题”选项卡中存在错误:

“ make:***没有规则将目标设置为all。停止。”

开发环境

+面向Java开发人员的Eclipse IDE(32位) 版本:开普勒服务发布2。

+ Eclipse的CDT插件

+ Windows 10 64位(我使用eclipse 32位,因为有时无法打开64位eclipse,解决方案是使用32位eclipse)

makefile

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

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

all : hello.dll

# $@ matches the target, $< matches the first dependency
hello.dll : HelloJNI.o
    gcc -Wl,--add-stdcall-alias -shared -o $@ $<

# $@ matches the target, $< matches the first dependency
HelloJNI.o : HelloJNI.c HelloJNI.h
    gcc -I"C:\Program Files (x86)\Java\jdk1.8.0_212\include" -I"C:\Program Files (x86)\Java\jdk1.8.0_212\include\win32" -c $< -o $@

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

clean :
    rm HelloJNI.h HelloJNI.o hello.dll

HelloJNI.c

#include <jni.h>
#include <stdio.h>
#include "HelloJNI.h"

JNIEXPORT void JNICALL Java_HelloJNI_sayHello(JNIEnv *env, jobject thisObj) {
   printf("Hello World!\n");
   return;
}

HelloJNI.h

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

#ifndef _Included_HelloJNI
#define _Included_HelloJNI
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     HelloJNI
 * Method:    sayHello
 * Signature: ()V
 */
JNIEXPORT void JNICALL Java_HelloJNI_sayHello
  (JNIEnv *, jobject);

#ifdef __cplusplus
}
#endif
#endif

HelloJNI.java

public class HelloJNI {
   static {
      System.loadLibrary("hello"); // hello.dll (Windows) or libhello.so (Unixes)
   }

   // Declare native method
   private native void sayHello();

   // Test Driver
   public static void main(String[] args) {
      new HelloJNI().sayHello();  // Allocate an instance and invoke the native method
   }
}

1 个答案:

答案 0 :(得分:1)

建议:

在makefile目标all之前,插入以下语句:

.PHONY: all

因此make实用程序不会尝试创建名为“ all”的文件

可能应该在目标clean

之前添加一个类似的语句
相关问题