javalinkerjava-native-interface

Undefined reference on shared library JNI


Okay, so I'm developing something With JNI + C, and the Java code calls a method on a .c that uses another compiled C code, so Java -> C -> C.

but when running, if I don use the second C code, things work fine, but when I use it:

java: symbol lookup error: /home/adriano/Área de Trabalho/229/DFT/libDFT.so: undefined symbol: newComplex

while newComplex is in complex.h

This is how I'm compiling the shared lib:

libDFT.so : DFT.o complex.o
gcc -shared -ansi -pedantic -Wall -O0 -g -ftest-coverage -fprofile-arcs -fPIC -I${JNI_INCLUDE} -I${JNI_INCLUDE}/linux/ -o $@ $<

Solution

  • This is wrong:

    libDFT.so : DFT.o complex.o
            gcc -shared ... -o $@ $<
    

    From documentation:

    $<
    The name of the first prerequisite.

    You want:

    libDFT.so : DFT.o complex.o
            gcc -shared ... -o $@ $^
    

    (The names of all the prerequisites.)