JNI make文件无效。多个定义

时间:2016-04-28 16:35:14

标签: java c makefile java-native-interface

所以我想创建一个jni库,但是make文件给出了一个我不太懂的奇怪错误。

/tmp/ccPWlMuy.o: In function `Java_GameLogic_setMap':
GameLogic.c:(.text+0x0): multiple definition of `Java_GameLogic_setMap'
/tmp/ccajmgva.o:GameLogic.c:(.text+0x0): first defined here
/tmp/ccPWlMuy.o: In function `Java_GameLogic_hello':
GameLogic.c:(.text+0x1c): multiple definition of `Java_GameLogic_hello'
/tmp/ccajmgva.o:GameLogic.c:(.text+0x1c): first defined here
collect2: ld returned 1 exit status
make: *** [GameLogic.o] Error 1

和make文件是:

# Define a variable for classpath
CLASS_PATH = .

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

all : libGameLogic.so

# $@ matches the target, $< matches the first dependancy
libGameLogic.so : GameLogic.o
    gcc -W1 -shared -o $@ $<

# $@ matches the target, $< matches the first dependancy
GameLogic.o : GameLogic.c GameLogic.h
    gcc -fPIC -I /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.38.x86_64/include -I /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.38.x86_64/include/linux -shared GameLogic.c -o libGameLogic.so Map.c GameLogic.c

GameLogic.h: GameLogic.class PlayGame.class Bot.class
    javah -classpath $(CLASS_PATH) GameLogic

GameLogic.class: GameLogic.java
    javac *.java    

PlayGame.class: PlayGame.java
    javac *.java

Bot.class: Bot.java
    javac *.java

clean :
    rm GameLogic.o libGameLogic.so

要运行make文件,我在make中输入make,这是它创建的错误。为此我需要它,以便JNI进行c调用,然后调用另一个c文件中的方法。

所以Java&lt; - &gt; JNI&lt; - &gt; GameLogic&lt; - &gt;图

按顺序。

非常感谢任何建议。

gcc -fPIC -I /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.38.x86_64/include -I /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.38.x86_64/include/linux -shared -o libGameLogic.so Map.c GameLogic.c
Map.h:7: warning: array ‘name’ assumed to have one element
Map.h:10: warning: array ‘map’ assumed to have one element
gcc -W1 -shared -o libGameLogic.so GameLogic.o
gcc: GameLogic.o: No such file or directory
gcc: no input files
make: *** [libGameLogic.so] Error 1
-bash-4.1$ 

My file system

1 个答案:

答案 0 :(得分:0)

您正在此行中编译和链接GameLogic.c两次:

# $@ matches the target, $< matches the first dependancy
GameLogic.o : GameLogic.c GameLogic.h
    gcc -fPIC -I /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.38.x86_64/include
    -I /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.38.x86_64/include/linux
    -shared GameLogic.c -o libGameLogic.so Map.c GameLogic.c