bytedeco / javacpp

The missing bridge between Java and native C++
Other
4.46k stars 581 forks source link

Cannot find the .so file when running the jar package. #690

Open mengpengfei opened 1 year ago

mengpengfei commented 1 year ago

The error message can be seen in one image.
image After I manually copied the libopencv_world.so.3.4 file over, the program ran normally.

However, the libopencv_world.so.3.4 file is already included in the jar package. Why wasn't the libopencv_world.so.3.4 file extracted to that directory, causing me to manually copy the file over when running the program?

I have tested all versions of javacpp, but this issue still remains unsolved. Is there any way to solve this problem?

mengpengfei commented 1 year ago

image From the above picture, it can be seen that the jar package already contains the so file. Except for the file libopencv_world.so.3.4, the other two .so files were successfully extracted to the path /root/.javacpp/cache/yolo-api-1.0-jar-with-dependencies.jar/*/***//linux-x86_64.

saudet commented 1 year ago

You should ask the author of that YoloApi project. I don't know anything about it.

saudet commented 1 year ago

Please set the "org.bytedeco.javacpp.logger.debug" system property to "true" to get more information on the console.

mengpengfei commented 1 year ago

Does it have anything to do with the caching function of javacpp? Some .so files will not be cached.

mengpengfei commented 1 year ago

Debug: Loading class org.bytedeco.javacpp.presets.javacpp Debug: Loading class org.bytedeco.javacpp.Loader Debug: Loading /root/.javacpp/cache/yolo-api-1.0-jar-with-dependencies.jar/org/bytedeco/javacpp/linux-x86_64/libjnijavacpp.so Debug: Loading class org.bytedeco.javacpp.presets.javacpp Debug: Loading class org.bytedeco.javacpp.Pointer Debug: Loading class top..yolo.YoloApi Debug: Loading /root/.javacpp/cache/yolo-api-1.0-jar-with-dependencies.jar/top//yolo/linux-x86_64/libdarknet.so Debug: Failed to load /root/.javacpp/cache/yolo-api-1.0-jar-with-dependencies.jar/top//yolo/linux-x86_64/libdarknet.so: java.lang.UnsatisfiedLinkError: /root/.javacpp/cache/yolo-api-1.0-jar-with-dependencies.jar/top//yolo/linux-x86_64/libdarknet.so: libopencv_world.so.3.4: cannot open shared object file: No such file or directory

Please set the "org.bytedeco.javacpp.logger.debug" system property to "true" to get more information on the console.

mengpengfei commented 1 year ago

Debug: Loading library darknet Debug: Failed to load for darknet: java.lang.UnsatisfiedLinkError: no darknet in java.library.path Debug: Loading /root/.javacpp/cache/yolo-api-1.0-jar-with-dependencies.jar/top//yolo/linux-x86_64/libjniYoloApi.so Debug: Failed to load /root/.javacpp/cache/yolo-api-1.0-jar-with-dependencies.jar/top//yolo/linux-x86_64/libjniYoloApi.so: java.lang.UnsatisfiedLinkError: /root/.javacpp/cache/yolo-api-1.0-jar-with-dependencies.jar/top/**/yolo/linux-x86_64/libjniYoloApi.so: libopencv_world.so.3.4: cannot open shared object file: No such file or directory Debug: Loading library jniYoloApi Debug: Failed to load for jniYoloApi: java.lang.UnsatisfiedLinkError: no jniYoloApi in java.library.path

saudet commented 1 year ago

It doesn't look like that YoloApi was designed to extract that library. Please report downstream.

mengpengfei commented 1 year ago

These codes were written by me alone, and the jar package was generated using a Maven plugin. Below is the configuration file information for Maven.

org.bytedeco javacpp 1.5.9 linux-x86_64 org.bytedeco javacpp 1.5.9
<build>
    <resources>

        <resource>

            <directory>src/main/java</directory>

            <includes>
                <include>**/*.so*</include>
            </includes>

            <filtering>false</filtering>
        </resource>
    </resources>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass></mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
mengpengfei commented 1 year ago

I write code independently without any upstream or downstream.

saudet commented 1 year ago

So, try to add "opencv_world@.3.4" to the @Platform(link=... annotation value as shown here: https://github.com/bytedeco/javacpp-presets/wiki/Create-New-Presets

mengpengfei commented 1 year ago

image

mengpengfei commented 1 year ago

Still printed the same error.

So, try to add "opencv_world@.3.4" to the @Platform(link=... annotation value as shown here: https://github.com/bytedeco/javacpp-presets/wiki/Create-New-Presets

saudet commented 1 year ago

Please set the "org.bytedeco.javacpp.logger.debug" system property to "true" to get more information on the console.

mengpengfei commented 1 year ago

image Debug: Loading class org.bytedeco.javacpp.presets.javacpp Debug: Loading class org.bytedeco.javacpp.Loader Debug: Loading /root/.javacpp/cache/yolo-api-1.0-jar-with-dependencies.jar/org/bytedeco/javacpp/linux-x86_64/libjnijavacpp.so Debug: Loading class org.bytedeco.javacpp.presets.javacpp Debug: Loading class org.bytedeco.javacpp.Pointer Debug: Loading class top.dg.yolo.YoloApi Debug: Loading library opencv_world.so.3.4 Debug: Failed to load for opencv_world.so.3.4: java.lang.UnsatisfiedLinkError: no opencv_world.so.3.4 in java.library.path Debug: Loading /root/.javacpp/cache/yolo-api-1.0-jar-with-dependencies.jar/top/dg/yolo/linux-x86_64/libdarknet.so Debug: Failed to load /root/.javacpp/cache/yolo-api-1.0-jar-with-dependencies.jar/top/dg/yolo/linux-x86_64/libdarknet.so: java.lang.UnsatisfiedLinkError: /root/.javacpp/cache/yolo-api-1.0-jar-with-dependencies.jar/top/dg/yolo/linux-x86_64/libdarknet.so: libopencv_world.so.3.4: cannot open shared object file: No such file or directory Debug: Loading library darknet Debug: Failed to load for darknet: java.lang.UnsatisfiedLinkError: no darknet in java.library.path Debug: Loading /root/.javacpp/cache/yolo-api-1.0-jar-with-dependencies.jar/top/dg/yolo/linux-x86_64/libjniYoloApi.so Debug: Failed to load /root/.javacpp/cache/yolo-api-1.0-jar-with-dependencies.jar/top/dg/yolo/linux-x86_64/libjniYoloApi.so: java.lang.UnsatisfiedLinkError: /root/.javacpp/cache/yolo-api-1.0-jar-with-dependencies.jar/top/dg/yolo/linux-x86_64/libjniYoloApi.so: libopencv_world.so.3.4: cannot open shared object file: No such file or directory Debug: Loading library jniYoloApi Debug: Failed to load for jniYoloApi: java.lang.UnsatisfiedLinkError: no jniYoloApi in java.library.path Exception in thread "main" java.lang.UnsatisfiedLinkError: no jniYoloApi in java.library.path at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1860) at java.lang.Runtime.loadLibrary0(Runtime.java:871) at java.lang.System.loadLibrary(System.java:1122) at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:1832) at org.bytedeco.javacpp.Loader.load(Loader.java:1423) at org.bytedeco.javacpp.Loader.load(Loader.java:1234) at org.bytedeco.javacpp.Loader.load(Loader.java:1210) at top.dg.yolo.YoloApi.(YoloApi.java:10) at top.dg.yolo.YoloTest.main(YoloTest.java:22) Caused by: java.lang.UnsatisfiedLinkError: /root/.javacpp/cache/yolo-api-1.0-jar-with-dependencies.jar/top/dg/yolo/linux-x86_64/libjniYoloApi.so: libopencv_world.so.3.4: cannot open shared object file: No such file or directory at java.lang.ClassLoader$NativeLibrary.load(Native Method) at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1934) at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1817) at java.lang.Runtime.load0(Runtime.java:810) at java.lang.System.load(System.java:1086) at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:1779) ... 5 more

Please set the "org.bytedeco.javacpp.logger.debug" system property to "true" to get more information on the console.

saudet commented 1 year ago

Debug: Failed to load for opencv_world.so.3.4: java.lang.UnsatisfiedLinkError: no opencv_world.so.3.4 in java.library.path

This means "opencv_world@.3.4" isn't in the @Platform(link=... annotation value Please add "opencv_world@.3.4" to the @Platform(link=... annotation value.

mengpengfei commented 1 year ago

It is ok now! thanks very much! I'm curious about the principle behind this setting. Is there any documentation available?

saudet commented 1 year ago

The @Platform annotation? Sure, there's a bit here: http://bytedeco.org/javacpp/apidocs/org/bytedeco/javacpp/annotation/Platform.html