3

I'm trying to compile a jni library for mac os x. My system is running Mountain Lion if that matters. I created a jni project in xcode and copied the source files into the project. It compiles well but had linking errors. Here is the error:

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)

What did I do wrong? It's having four source files main.c, floodfill.c, jumppointsearch.c and queue.c. I don't understand what they do since I'm not a C programmer. I'm just compiling them for a friend on this forum.

EDIT:

This is the project property page 'Build Phases' for this project.

enter image description here

Thanks.

Sri Harsha Chilakapati
  • 11,744
  • 6
  • 50
  • 91

1 Answers1

0

You can try with super simple sample code. All you need is a simple C code and Java class that will load library.

I suggest to take a look here:

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

That's super simple Hello World application where all you have to do is to call simple C code:

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

  printf("Hello world!\n");

}

from Java code:

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();
  }
}

If you are using XCode, you should be able to use command line tools as well. Take a look here, how to check whether you have them installed:

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

Have fun with JNI ;)

Oo.oO
  • 12,464
  • 3
  • 23
  • 45
  • Thanks for the answer, but I already got this working. The error is that I have it setup with objective C as the language as default. All I had to do is to change it to C++ and it worked. – Sri Harsha Chilakapati Nov 08 '16 at 02:41