Matthew Hewitt Matthew Hewitt - 7 months ago 19
Java Question

JNI make file is not working. Multiple definitions

So I am trying to make a jni library but the make file gives a strange error that I don't really understand.

/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


and the make file is:

# 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


To run the make file I type in make into the terminal and this is the error that it creates. For this I need to have it so that JNI makes a c call which then calls a method in another c file.

So Java <-> JNI <-> GameLogic <-> Map

In that order.

Any advice is much appreciated many thanks.




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

Answer

You are compiling and linking GameLogic.c twice in this line:

# $@ 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