简体   繁体   中英

loading a c++ library.so in java raises the error: undefined symbol: XOpenDisplay

This question follows this one . I am able to find the library but when it is loading it raises the following error

java.lang.UnsatisfiedLinkError: /home/name/Documents/Development/GitLocalRepo/hidden-mathLibrary/hidden/lib/Distribution/libgtengine.so.3.7: /home/name/Documents/Development/GitLocalRepo/hidden-mathLibrary/hidden/lib/Distribution/libgtengine.so.3.7: undefined symbol: XOpenDisplay

the code raising the error is the following:

public class Frame {

    static {
        System.loadLibrary( "gtengine" );   // <- error occurs here
    }

    public interface libWrapper extends Library {

    libWrapper INSTANCE = (libWrapper)
            Native.loadLibrary(
                    "gtengine",
                    libWrapper.class );

    Pointer FrameCstructor(String name, long parent,
            double x, double y, double z,
            double rotX, double rotY, double rotZ,
            double vX, double vY, double vZ,
            double angVx, double angVy, double angVz,
            double accX, double accY, double accZ,
            double angAccX, double angAccY, double angAccZ,
            boolean addToFramelist);
    }

    public static native Pointer FrameCstructor(String name, long parent,
        double x, double y, double z,
        double rotX, double rotY, double rotZ,
        double vX, double vY, double vZ,
        double angVx, double angVy, double angVz,
        double accX, double accY, double accZ,
        double angAccX, double angAccY, double angAccZ,
        boolean addToFramelist);

    private Pointer ptrToCFrame;

    public Frame(String name, int parent,
        double x, double y, double z,
        double rotX, double rotY, double rotZ,
        double vX, double vY, double vZ,
        double angVx, double angVy, double angVz,
        double accX, double accY, double accZ,
        double angAccX, double angAccY, double angAccZ,
        boolean addToFramelist) {

    System.out.println("library: " + System.getProperty( "java.library.path" ));

    ptrToCFrame = libWrapper.INSTANCE.FrameCstructor( name, parent,
            x, y, z, rotX, rotY, rotZ,
            vX, vY, vZ, angVx, angVy, angVz,
            accX, accY, accZ, angAccX, angAccY, angAccZ,
            addToFramelist );
    }
}

Is it due to the presence of some references to X11 in the library? It will be a huge job to remove it from the library! I am working on fedora 25.

Thanks

As you can see here gtengine uses X11 library. Which, in your case, looks missing. XOpenDisplay function is in xlib library.

Take a look here:

https://github.com/mkowsiak/jnicookbook/blob/master/recipes/recipeNo023/Makefile

In this sample code you can see how to deal with JNI code that requires some other code to work.

Just make sure that library with "XOpenDisplay" (xlib - as already mentioned by sithereal) is visible to JVM (eg add it to LD_LIBRARY_PATH or user -Wl,-rpath while building your JNI code).

Have fun with JNI.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM