2013-10-11 50 views
3

我正在嘗試編譯mac os x的jni庫。如果有問題,我的系統正在運行Mountain Lion。我在xcode中創建了一個jni項目,並將源文件複製到項目中。它編譯良好,但有鏈接錯誤。 以下是錯誤:Mac OS X上的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,jumppointsearch.cqueue.c。我不明白他們做什麼,因爲我不是C程序員。我只是將它們編譯給this forum的朋友。

編輯:

這是項目屬性頁 '構建階段' 這個項目。

enter image description here

謝謝。

+0

@Dayalrai我剛纔用的IDE。我不知道命令是什麼。 –

+0

@Dayalrai我不明白你的意思。我已經將JavaVM.framework添加到框架列表中,並將includes文件夾設置爲JDK附帶的文件夾。 –

+0

@Dayalrai我添加了「Build Phases」屬性頁面的屏幕截圖。 –

回答

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, d也能夠使用命令行工具。看看這裏,如何檢查是否安裝它們:

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

有樂趣JNI)

+0

感謝您的回答,但我已經得到了這個工作。錯誤在於我將它設置爲目標C作爲默認語言。我所要做的就是將其改爲C++,並且工作。 –

相關問題