mafioso mafioso - 1 month ago 5
C Question

Compiling project in Linux terminal doesn't work

I have a

Compile.sh
file.

This one works like a charm:

cd src
javac model/JNIResultSet.java
javah -jni model.JNIResultSet
cp model_JNIResultSet.h ./../bin/
cd ..

cd bin

gcc -fPIC -o libspieler.so -shared -I/usr/java/jdk1.8.0_73/include/ SharedTable.c -lc

java -Djava.library.path=./../bin/ app.Main


My problem is that I don't want to have my sources in the bin folder.

I want to have them in a separate folder.

For that my script looks like this one:

cd src
javac model/JNIResultSet.java
javah -jni model.JNIResultSet
cp model_JNIResultSet.h ./../data/
cd ..

cd data

gcc -fPIC -o libspieler.so -shared -I/usr/java/jdk1.8.0_73/include/ SharedTable.c -lc
cd ..
cd bin
java -Djava.library.path=./../data/ app.Main


I don't know why this one isn't working. I get no exception but the program also doesn't work correctly. Do you know how to fix it?

Answer

The working script has:

cd bin
gcc -fPIC -o libspieler.so -shared -I/usr/java/jdk1.8.0_73/include/ SharedTable.c

And the other version has:

cd data
gcc -fPIC -o libspieler.so -shared -I/usr/java/jdk1.8.0_73/include/ SharedTable.c -lc

So SharedTable.c must be in the bin directory, and the gcc command can't find it because it's no longer in the current directory. Try using a relative path instead:

gcc -fPIC -o libspieler.so -shared -I/usr/java/jdk1.8.0_73/include/ ../bin/SharedTable.c -lc