3

我正在尝试为 mac os x 编译一个 jni 库。如果这很重要,我的系统正在运行 Mountain Lion。我在 xcode 中创建了一个 jni 项目并将源文件复制到项目中。它编译得很好,但有链接错误。这是错误:

Undefined symbols for architecture x86_64:
  "_init_queue", referenced from:
      _floodfill in floodfill.o
  "_jumpPointSearch", referenced from:
      _Java_com_clashtune_pathfind_Pathfinder_jumpPointSearchNative in main.o
     (maybe you meant: _Java_com_clashtune_pathfind_Pathfinder_jumpPointSearchNative)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我做错了什么?它有四个源文件main.c,floodfill.c和. 我不明白他们在做什么,因为我不是 C 程序员。我只是在这个论坛上为朋友编译它们。jumppointsearch.cqueue.c

编辑:

这是该项目的项目属性页面“构建阶段”。

在此处输入图像描述

谢谢。

4

1 回答 1

0

您可以尝试使用超级简单的示例代码。您所需要的只是一个简单的 C 代码和将加载库的 Java 类。

我建议看看这里:

http://jnicookbook.owsiak.org/recipe-No-001/

这是一个超级简单的 Hello World 应用程序,您所要做的就是调用简单的 C 代码:

JNIEXPORT void JNICALL Java_recipeNo001_HelloWorld_displayMessage
  (JNIEnv *env, jclass obj) {

  printf("Hello world!\n");

}

来自Java代码:

package recipeNo001;

public class HelloWorld {

  /* This is the native method we want to call */
  public static native void displayMessage();

  /* Inside static block we will load shared library */
  static {
    System.loadLibrary("HelloWorld");
  }

  public static void main(String[] args) {
    /* This message will help you determine whether
        LD_LIBRARY_PATH is correctly set
    */
    System.out.println("library: "
      + System.getProperty("java.library.path"));

    /* Call to shared library */
    HelloWorld.displayMessage();
  }
}

如果您使用的是 XCode,您也应该能够使用命令行工具。看看这里,如何检查你是否安装了它们:

http://jnicookbook.owsiak.org/introduction/

玩得开心 JNI ;)

于 2016-11-07T20:49:02.130 回答