bytedeco / javacpp-presets

The missing Java distribution of native C++ libraries
Other
2.62k stars 730 forks source link

build custom module of javacpp-presets error #920

Open nanguantong opened 3 years ago

nanguantong commented 3 years ago

Hi,

I followed the step in https://github.com/bytedeco/javacpp-presets/wiki/Create-New-Presets and https://github.com/bytedeco/javacpp-presets/wiki/Building-on-Windows

then run "mvn install -Djavacpp.platform=windows-x86 --projects .,libmpeg", error found:

jnilibmpeg.obj : error LNK2001: unresolved external symbol __imp_ps_demuxer_create

ps_demuxer_create is the function name in the external cpp lib.

my configures in the following:

javacpp-presets\libmpeg\src\main\java\org\bytedeco\libmpeg\presets\libmpeg.java:

@Properties(inherit=javacpp.class, target="org.bytedeco.libmpeg", global="org.bytedeco.libmpeg.global.libmpeg", value={
    @Platform(
            value = {
                    "windows-x86",
                    "windows-x86_64"
            },
            include = {
            "<mpeg-ps.h>"
       }, link = {"libmpeg"}
    )
        , @Platform(value = "windows", preload = "libmpeg")
})

public class libmpeg implements InfoMapper {
    static { Loader.checkVersion("org.bytedeco", "libmpeg"); }

    public void map(InfoMap infoMap) {
          infoMap.put(new Info("_WIN32", "NAN_API", "NOINLINE").cppTypes().annotations())
                 .put(new Info("NAN_EXPORT").cppTypes().define(false));
    }
}

javacpp-presets\libmpeg\src\main\java9\module-info.java:

module org.bytedeco.libmpeg {
  requires transitive org.bytedeco.javacpp;
  exports org.bytedeco.libmpeg.global;
  exports org.bytedeco.libmpeg.presets;
  exports org.bytedeco.libmpeg;
}

pom.xml:

<profiles>
    <profile>
      <id>msvc</id>
      <activation>
        <os><family>windows</family></os>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.bytedeco</groupId>
            <artifactId>javacpp</artifactId>
            <configuration>
              <properties>${javacpp.platform}</properties>
              <compilerOptions>
                <compilerOption>/MT</compilerOption>
              </compilerOptions>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
saudet commented 3 years ago

It looks like you're not importing/exporting symbols from your library correctly: https://docs.microsoft.com/en-us/cpp/cpp/dllexport-dllimport

nanguantong commented 3 years ago

It looks like you're not importing/exporting symbols from your library correctly: https://docs.microsoft.com/en-us/cpp/cpp/dllexport-dllimport

I did it in mpeg_ps.h, It's still the same error:

#ifndef _mpeg_ps_h_
#define _mpeg_ps_h_

#include <stdint.h>
#include <stddef.h>

#if defined(_WIN32)
#define WIN32_LEAN_AND_MEAN
//#define NAN_CALL __cdecl
#if defined(NAN_EXPORT)
#define NAN_API __declspec(dllexport)
#else
#define NAN_API __declspec(dllimport)
#endif
#define NOINLINE __declspec(noinline)
#elif defined(__GNUC__)
#define NAN_CALL
#define NAN_API __attribute__((visibility("default")))
#define NOINLINE __attribute__((noinline))
#else
#define NAN_CALL
#define NAN_API
#define NOINLINE
#endif

#ifdef __cplusplus
extern "C" {
#endif

typedef void(*ps_demuxer_onpacket)(void* param, int stream, int codecid, int flags, int64_t pts, int64_t dts, const void* data, size_t bytes);
NAN_API struct ps_demuxer_t* ps_demuxer_create(ps_demuxer_onpacket onpacket, void* param);

#ifdef __cplusplus
}
#endif
#endif /* !_mpeg_ps_h_ */
nanguantong commented 3 years ago

@saudet Can you please help me solve this issue?

saudet commented 3 years ago

Your code expects to link with a DLL, where is libmpeg.dll?

nanguantong commented 3 years ago

Your code expects to link with a DLL, where is libmpeg.dll?

In cppbuild.sh to build local library:

windows-*)
        echo ""
        echo "--------------------"
        echo "Building"
        echo "--------------------"
        echo ""

        if [[ $PLATFORM == "windows-x86" ]]; then
            make -j $MAKEJ RELEASE=1 PLATFORM=$PLATFORM ARCH=32 V=0
        else
            make -j $MAKEJ RELEASE=1 PLATFORM=$PLATFORM ARCH=64 V=0
        fi
......

====> libmpeg.dll

saudet commented 3 years ago

What does cl.exe /? return?

nanguantong commented 3 years ago

.. x86 Microsoft (R) C/C++ .. 19.16.27042 (C) Microsoft Corporation

saudet commented 3 years ago

What about dumpbin /headers libmpeg.lib and dumpbin /headers libmpeg.dll?

nanguantong commented 3 years ago

It may be the problem caused by x86 or x64 visual studio prompt, I'll try it out

nanguantong commented 3 years ago

In 64-bit windows, I built zlib-1.2.11-1.5.4-SNAPSHOT-windows-x86.jar and zlib-1.2.11-1.5.4-SNAPSHOT-windows-x86_64.jar to "C:\Users\xxxx.m2\repository\org\bytedeco\zlib\1.2.11-1.5.4-SNAPSHOT" by the steps of https://github.com/bytedeco/javacpp-presets/wiki/Create-New-Presets , then running error:

no jnizlib in java.library.path
java.lang.UnsatisfiedLinkError: no jnizlib in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1860)
    at java.lang.Runtime.loadLibrary0(Runtime.java:870)
    at java.lang.System.loadLibrary(System.java:1122)

@saudet what is the reason for this?

saudet commented 3 years ago

It means it's not finding libjnizlib.dll anywhere. Where is it?

nanguantong commented 3 years ago

image

saudet commented 3 years ago

Could you set the "org.bytedeco.javacpp.logger.debug" system property to "true" and let me know what gets displayed on the console when it tries to load that?

nanguantong commented 3 years ago
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.javacpp.Loader
Debug: Loading C:\Users\Think\.javacpp\cache\javacpp-1.5.4-SNAPSHOT-windows-x86_64.jar\org\bytedeco\javacpp\windows-x86_64\api-ms-win-crt-locale-l1-1-0.dll
Debug: Loading C:\Users\Think\.javacpp\cache\javacpp-1.5.4-SNAPSHOT-windows-x86_64.jar\org\bytedeco\javacpp\windows-x86_64\api-ms-win-crt-string-l1-1-0.dll
Debug: Loading C:\Users\Think\.javacpp\cache\javacpp-1.5.4-SNAPSHOT-windows-x86_64.jar\org\bytedeco\javacpp\windows-x86_64\api-ms-win-crt-stdio-l1-1-0.dll
Debug: Loading C:\Users\Think\.javacpp\cache\javacpp-1.5.4-SNAPSHOT-windows-x86_64.jar\org\bytedeco\javacpp\windows-x86_64\api-ms-win-crt-math-l1-1-0.dll
Debug: Loading C:\Users\Think\.javacpp\cache\javacpp-1.5.4-SNAPSHOT-windows-x86_64.jar\org\bytedeco\javacpp\windows-x86_64\api-ms-win-crt-heap-l1-1-0.dll
Debug: Loading C:\Users\Think\.javacpp\cache\javacpp-1.5.4-SNAPSHOT-windows-x86_64.jar\org\bytedeco\javacpp\windows-x86_64\api-ms-win-crt-runtime-l1-1-0.dll
Debug: Loading C:\Users\Think\.javacpp\cache\javacpp-1.5.4-SNAPSHOT-windows-x86_64.jar\org\bytedeco\javacpp\windows-x86_64\api-ms-win-crt-convert-l1-1-0.dll
Debug: Loading C:\Users\Think\.javacpp\cache\javacpp-1.5.4-SNAPSHOT-windows-x86_64.jar\org\bytedeco\javacpp\windows-x86_64\api-ms-win-crt-environment-l1-1-0.dll
Debug: Loading C:\Users\Think\.javacpp\cache\javacpp-1.5.4-SNAPSHOT-windows-x86_64.jar\org\bytedeco\javacpp\windows-x86_64\api-ms-win-crt-time-l1-1-0.dll
Debug: Loading C:\Users\Think\.javacpp\cache\javacpp-1.5.4-SNAPSHOT-windows-x86_64.jar\org\bytedeco\javacpp\windows-x86_64\api-ms-win-crt-filesystem-l1-1-0.dll
Debug: Loading C:\Users\Think\.javacpp\cache\javacpp-1.5.4-SNAPSHOT-windows-x86_64.jar\org\bytedeco\javacpp\windows-x86_64\api-ms-win-crt-utility-l1-1-0.dll
Debug: Loading C:\Users\Think\.javacpp\cache\javacpp-1.5.4-SNAPSHOT-windows-x86_64.jar\org\bytedeco\javacpp\windows-x86_64\api-ms-win-crt-multibyte-l1-1-0.dll
Debug: Loading C:\Users\Think\.javacpp\cache\javacpp-1.5.4-SNAPSHOT-windows-x86_64.jar\org\bytedeco\javacpp\windows-x86_64\api-ms-win-core-string-l1-1-0.dll
Debug: Loading C:\Users\Think\.javacpp\cache\javacpp-1.5.4-SNAPSHOT-windows-x86_64.jar\org\bytedeco\javacpp\windows-x86_64\api-ms-win-core-errorhandling-l1-1-0.dll
Debug: Loading C:\Users\Think\.javacpp\cache\javacpp-1.5.4-SNAPSHOT-windows-x86_64.jar\org\bytedeco\javacpp\windows-x86_64\api-ms-win-core-timezone-l1-1-0.dll
Debug: Loading C:\Users\Think\.javacpp\cache\javacpp-1.5.4-SNAPSHOT-windows-x86_64.jar\org\bytedeco\javacpp\windows-x86_64\api-ms-win-core-file-l1-1-0.dll
Debug: Loading C:\Users\Think\.javacpp\cache\javacpp-1.5.4-SNAPSHOT-windows-x86_64.jar\org\bytedeco\javacpp\windows-x86_64\api-ms-win-core-namedpipe-l1-1-0.dll
Debug: Loading C:\Users\Think\.javacpp\cache\javacpp-1.5.4-SNAPSHOT-windows-x86_64.jar\org\bytedeco\javacpp\windows-x86_64\api-ms-win-core-handle-l1-1-0.dll
Debug: Loading C:\Users\Think\.javacpp\cache\javacpp-1.5.4-SNAPSHOT-windows-x86_64.jar\org\bytedeco\javacpp\windows-x86_64\api-ms-win-core-file-l2-1-0.dll
Debug: Loading C:\Users\Think\.javacpp\cache\javacpp-1.5.4-SNAPSHOT-windows-x86_64.jar\org\bytedeco\javacpp\windows-x86_64\api-ms-win-core-heap-l1-1-0.dll
Debug: Loading C:\Users\Think\.javacpp\cache\javacpp-1.5.4-SNAPSHOT-windows-x86_64.jar\org\bytedeco\javacpp\windows-x86_64\api-ms-win-core-libraryloader-l1-1-0.dll
Debug: Loading C:\Users\Think\.javacpp\cache\javacpp-1.5.4-SNAPSHOT-windows-x86_64.jar\org\bytedeco\javacpp\windows-x86_64\api-ms-win-core-synch-l1-1-0.dll
Debug: Loading C:\Users\Think\.javacpp\cache\javacpp-1.5.4-SNAPSHOT-windows-x86_64.jar\org\bytedeco\javacpp\windows-x86_64\api-ms-win-core-processthreads-l1-1-0.dll
Debug: Loading C:\Users\Think\.javacpp\cache\javacpp-1.5.4-SNAPSHOT-windows-x86_64.jar\org\bytedeco\javacpp\windows-x86_64\api-ms-win-core-processenvironment-l1-1-0.dll
Debug: Loading C:\Users\Think\.javacpp\cache\javacpp-1.5.4-SNAPSHOT-windows-x86_64.jar\org\bytedeco\javacpp\windows-x86_64\api-ms-win-core-datetime-l1-1-0.dll
Debug: Loading C:\Users\Think\.javacpp\cache\javacpp-1.5.4-SNAPSHOT-windows-x86_64.jar\org\bytedeco\javacpp\windows-x86_64\api-ms-win-core-localization-l1-2-0.dll
Debug: Loading C:\Users\Think\.javacpp\cache\javacpp-1.5.4-SNAPSHOT-windows-x86_64.jar\org\bytedeco\javacpp\windows-x86_64\api-ms-win-core-sysinfo-l1-1-0.dll
Debug: Loading C:\Users\Think\.javacpp\cache\javacpp-1.5.4-SNAPSHOT-windows-x86_64.jar\org\bytedeco\javacpp\windows-x86_64\api-ms-win-core-synch-l1-2-0.dll
Debug: Loading C:\Users\Think\.javacpp\cache\javacpp-1.5.4-SNAPSHOT-windows-x86_64.jar\org\bytedeco\javacpp\windows-x86_64\api-ms-win-core-console-l1-1-0.dll
Debug: Loading C:\Users\Think\.javacpp\cache\javacpp-1.5.4-SNAPSHOT-windows-x86_64.jar\org\bytedeco\javacpp\windows-x86_64\api-ms-win-core-debug-l1-1-0.dll
Debug: Loading C:\Users\Think\.javacpp\cache\javacpp-1.5.4-SNAPSHOT-windows-x86_64.jar\org\bytedeco\javacpp\windows-x86_64\api-ms-win-core-rtlsupport-l1-1-0.dll
Debug: Loading C:\Users\Think\.javacpp\cache\javacpp-1.5.4-SNAPSHOT-windows-x86_64.jar\org\bytedeco\javacpp\windows-x86_64\api-ms-win-core-processthreads-l1-1-1.dll
Debug: Loading C:\Users\Think\.javacpp\cache\javacpp-1.5.4-SNAPSHOT-windows-x86_64.jar\org\bytedeco\javacpp\windows-x86_64\api-ms-win-core-file-l1-2-0.dll
Debug: Loading C:\Users\Think\.javacpp\cache\javacpp-1.5.4-SNAPSHOT-windows-x86_64.jar\org\bytedeco\javacpp\windows-x86_64\api-ms-win-core-profile-l1-1-0.dll
Debug: Loading C:\Users\Think\.javacpp\cache\javacpp-1.5.4-SNAPSHOT-windows-x86_64.jar\org\bytedeco\javacpp\windows-x86_64\api-ms-win-core-memory-l1-1-0.dll
Debug: Loading C:\Users\Think\.javacpp\cache\javacpp-1.5.4-SNAPSHOT-windows-x86_64.jar\org\bytedeco\javacpp\windows-x86_64\api-ms-win-core-util-l1-1-0.dll
Debug: Loading C:\Users\Think\.javacpp\cache\javacpp-1.5.4-SNAPSHOT-windows-x86_64.jar\org\bytedeco\javacpp\windows-x86_64\api-ms-win-core-interlocked-l1-1-0.dll
Debug: Loading C:\Users\Think\.javacpp\cache\javacpp-1.5.4-SNAPSHOT-windows-x86_64.jar\org\bytedeco\javacpp\windows-x86_64\ucrtbase.dll
Debug: Loading C:\Users\Think\.javacpp\cache\javacpp-1.5.4-SNAPSHOT-windows-x86_64.jar\org\bytedeco\javacpp\windows-x86_64\vcruntime140.dll
Debug: Loading C:\Users\Think\.javacpp\cache\javacpp-1.5.4-SNAPSHOT-windows-x86_64.jar\org\bytedeco\javacpp\windows-x86_64\vcruntime140_1.dll
Debug: Loading C:\Users\Think\.javacpp\cache\javacpp-1.5.4-SNAPSHOT-windows-x86_64.jar\org\bytedeco\javacpp\windows-x86_64\msvcp140.dll
Debug: Loading C:\Users\Think\.javacpp\cache\javacpp-1.5.4-SNAPSHOT-windows-x86_64.jar\org\bytedeco\javacpp\windows-x86_64\msvcp140_1.dll
Debug: Loading C:\Users\Think\.javacpp\cache\javacpp-1.5.4-SNAPSHOT-windows-x86_64.jar\org\bytedeco\javacpp\windows-x86_64\concrt140.dll
Debug: Loading C:\Users\Think\.javacpp\cache\javacpp-1.5.4-SNAPSHOT-windows-x86_64.jar\org\bytedeco\javacpp\windows-x86_64\vcomp140.dll
Debug: Loading C:\Users\Think\.javacpp\cache\javacpp-1.5.4-SNAPSHOT-windows-x86_64.jar\org\bytedeco\javacpp\windows-x86_64\jnijavacpp.dll
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.javacpp.Pointer
[]
Debug: Loading class org.bytedeco.zlib.global.zlib
Debug: Loading class org.bytedeco.zlib.global.zlib
Debug: Loading library jnizlib
Debug: Failed to load for jnizlib: java.lang.UnsatisfiedLinkError: no jnizlib in java.library.path

no jnizlib in java.library.path
java.lang.UnsatisfiedLinkError: no jnizlib in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1860)
    at java.lang.Runtime.loadLibrary0(Runtime.java:870)
    at java.lang.System.loadLibrary(System.java:1122)
    at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:1683)
    at org.bytedeco.javacpp.Loader.load(Loader.java:1300)
    at org.bytedeco.javacpp.Loader.load(Loader.java:1123)
    at org.bytedeco.zlib.global.zlib.<clinit>(zlib.java:12)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:348)
    at org.bytedeco.javacpp.Loader.load(Loader.java:1190)
    at org.bytedeco.javacpp.Loader.load(Loader.java:1123)
    at org.bytedeco.zlib.z_stream.<clinit>(z_stream.java:14)
    at com.media.gbs.domain.codec.TestSvac.openInputSvac(TestSvac.java:42)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:110)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:58)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:38)
    at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:62)
    at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
    at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
    at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
    at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:118)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:182)
    at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:164)
    at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:412)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
    at java.lang.Thread.run(Thread.java:748)
saudet commented 3 years ago

Right, so that just means it's not finding libjnizlib.dll. You'll need to put those JAR files in your class path.

nanguantong commented 3 years ago

As the contrast of ffmpeg from gradle mavenCentral automatically downloaded in C:\Users\Think.gradle\caches\modules-2\files-2.1\org.bytedeco\ffmpeg\4.3.1-1.5.4-SNAPSHOT\2440042004c1a860a43f7f91efe8fce4f7e5621f\ffmpeg-4.3.1-1.5.4-SNAPSHOT-windows-x86_64.jar, then loaded to C:\Users\Think.javacpp\cache\ffmpeg-4.3.1-1.5.4-SNAPSHOT-windows-x86_64.jar,it's ok while running.

But the zlib custom preset built from mavenLocal manually to C:\Users\Think.m2\repository\org\bytedeco\svacdecoder\0.100-1.5.4-SNAPSHOT,not found in C:\Users\Think.gradle\caches\modules-2\files-2.1..., so how could i do it ? not putting those JAR files in my class path manually .

saudet commented 3 years ago

You mean how to use those JARs from Gradle? We can add repositories { mavenLocal() } for that like this: https://github.com/bytedeco/gradle-javacpp/blob/master/samples/zlib/build.gradle#L10

nanguantong commented 3 years ago

Yes, how to use local custom preset jar (e.g. zlib) without putting jars file to class path manually ?

my build.gradle:

repositories {
        mavenLocal()
        mavenCentral()
        maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
        maven { url = 'https://jitpack.io' } // Allows annotations past Java 8 to be used
    }

dependencies {
    compile group: 'org.bytedeco', name: 'zlib', version: "1.2.11-1.5.4-SNAPSHOT"
}
saudet commented 3 years ago

You mean the artifacts with classifiers? Do something like this, but for Windows instead of Android: https://github.com/bytedeco/javacpp-presets/wiki/Reducing-the-Number-of-Dependencies#including-binaries-only-for-mobile-platforms

nanguantong commented 3 years ago

No, I means that how the javacpp to load the built local custom presets?

And I set the class path, the same error: no jnizlib in java.library.path

image

saudet commented 3 years ago

It doesn't change anything whether they were built locally or not. They are loaded the same way.

nanguantong commented 3 years ago

Right, so that just means it's not finding libjnizlib.dll.

You'll need to put those JAR files in your class path. -----> How to do it?

My jars are in C:\Users\Think.m2\repository\org\bytedeco\zlib\1.2.11-1.5.4-SNAPSHOT: image generated by mvn install -Djavacpp.platform=windows-x86 (or windows-86_64) --projects .,zlib

And What else do I need to do to make it work?

nanguantong commented 3 years ago

Yeah, while I wrote compile group: 'org.bytedeco', name: 'zlib-platform', version: "1.2.11-1.5.4-SNAPSHOT" instead of compile group: 'org.bytedeco', name: 'zlib', version: "1.2.11-1.5.4-SNAPSHOT" in build.gradle

it works ok.

In org\bytedeco\javacpp\Loader.java: findResources:

        while (url == null && !urls.hasMoreElements() && path.length() > 0) {
            int n = path.lastIndexOf('/', path.length() - 2);
            if (n >= 0) {
                path = path.substring(0, n + 1);
            } else {
                path = "";
            }
            urls = classLoader.getResources(path + name);
        }
        while (urls.hasMoreElements() && (maxLength < 0 || array.size() < maxLength)) {
            url = urls.nextElement();
            if (!array.contains(url)) {
                array.add(url);
            }
        }
        return array.toArray(new URL[array.size()]);
   return ---> ` jar:file:/C:/Users/Think/.m2/repository/org/bytedeco/zlib/1.2.11-1.5.4-SNAPSHOT/zlib-1.2.11-1.5.4-SNAPSHOT-windows-x86_64.jar!/org/bytedeco/zlib/windows-x86_64/jnizlib.dll`  (!!! found reference class path automatically), otherwise return null.
nanguantong commented 3 years ago

@saudet Other question please:How to packet all dependency dlls to output jar?

e.g.

in cppbuild\windows-x86\lib: a.lib a.dll b.dll c.dll in @Platform(value = "windows", link = { "a" })

only a.dll in output jar, I want to use a.dll b.dll c.dll in output jar.

saudet commented 3 years ago

Add preload={"b", "c"}

nanguantong commented 1 year ago

Hi, @saudet

Other question please:How to packet all dependency dlls to output jar?

e.g.

in cppbuild\windows-x86\lib: a.lib a.dll dir1/b.dll dir2/c.dll in https://github.com/platform(value = "windows", link = { "a" })

I need to packet a.dll dir1/b.dll dir2/c.dll in output jar.

saudet commented 1 year ago

Include those dirs in the linkPath, in the pom.xml file.

nanguantong commented 1 year ago

@saudet How to keep the original lib directory in the output jar? e.g. a.dll dir1 ----b.dll dir2 ----c.dll ----e.cfg

nanguantong commented 1 year ago

And another problem as following:

D:/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/12.2.0/../../../../i686-w64-mingw32/bin/ld.exe: E:\opensource\javacpp\javacpp-presets-1.5.8\xxx\cppbuild\windows-x86\lib/test.lib(test.o):test.c:(.text+0x246): undefined reference totttttt(long)@4'`

build command: [INFO] g++ -IE:\opensource\javacpp\javacpp-presets-1.5.8\xxx\cppbuild\windows-x86_64\include -IC:\Users\user\.jdks\corretto-11.0.18\include -IC:\Users\user\.jdks\corretto-11.0.18\include\win32 E:\opensource\javacpp\javacpp-presets-1.5.8\xxx\target\native\org\bytedeco\xxx\windows-x86_64\jnixxx.cpp E:\opensource\javacpp\javacpp-presets-1.5.8\xxx\target\native\org\bytedeco\xxx\windows-x86_64\jnijavacpp.cpp -march=x86-64 -m64 -O3 -s -std=c++11 -static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -lgcc -lgcc_eh -lpthread -Wl,-Bdynamic -D_JNI_IMPLEMENTATION_ -Wl,--kill-at -Wall -fPIC -shared -o jnixxx.dll -LE:\opensource\javacpp\javacpp-presets-1.5.8\xxx\cppbuild\windows-x86\lib -lxxx -lplayer -lpsapi

The function "tttttt" is in the lib "-lplayer", that is x86 arch.

What could be the reason for this?

saudet commented 1 year ago

How to keep the original lib directory in the output jar?

We can bundle that kind of thing as "resources" and do whatever we need that way. See, for example, numpy: https://github.com/bytedeco/javacpp-presets/blob/master/numpy/src/main/java/org/bytedeco/numpy/presets/numpy.java#L76

What could be the reason for this?

It looks like you're trying to link a library that was made for MSVC using GCC? There's probably some flag for that somewhere, but I would recommend using MSVC.

nanguantong commented 1 year ago

How to keep the original lib directory in the output jar?

We can bundle that kind of thing as "resources" and do whatever we need that way. See, for example, numpy: https://github.com/bytedeco/javacpp-presets/blob/master/numpy/src/main/java/org/bytedeco/numpy/presets/numpy.java#L76

What could be the reason for this?

It looks like you're trying to link a library that was made for MSVC using GCC? There's probably some flag for that somewhere, but I would recommend using MSVC.

I need to link a library that was made for MSVC using GCC, don't know which flags?
It was possible to use it like this before.

nanguantong commented 1 year ago

the dir struct as following:

root_dir
----player.lib
----player.dll
----a.dll
----k.cfg
----dir1
--------b.dll
--------c.cfg
----dir2
--------dir3
------------d.log
--------e.dll
--------f.cfg

the decoder.lib is built and generated by the cppbuild.sh.

and I expect to output output.jar that dir struct is the same as above. so the java generate code as following:

@Platform(value = "windows-x86_64", link = { "player", "decoder#" },
                preload = { "a", "dir1/b", "dir2/e"},
                resource= {"dir1", "dir2""},
               // ....... ?

Is that correct? give some advice, thanks. @saudet

saudet commented 1 year ago

You won't be able to use @Platform link and preload like that at runtime. You'll need to cache the resources manually something like this and call Loader.load() manually on the files that you want: https://github.com/bytedeco/javacpp-presets/blob/master/numpy/src/main/java/org/bytedeco/numpy/presets/numpy.java#L93

nanguantong commented 1 year ago

So simply could you please write a class and function demo as above dir struct?

saudet commented 1 year ago

Actually, it might work with preloadresource, but I don't think I've tested it that way. Try something like @Platform(link = {"player", "decoder#"}, preload = {"a", "b", "e"}, preloadresource = {"dir1", "dir2"}).

nanguantong commented 1 year ago

preloadresource

Not work, output as following:

output.jar ----player.dll ----a.dll ----dir1 ----dir2 ----jnidecoder.dll

the dir1 and dir2 have no files, and mvn clean install -Djavacpp.platform=windows-x86_64 --projects decoder output: [WARNING] Could not find library b [WARNING] Could not find library e

saudet commented 1 year ago

You're still going to need to specify a preloadpath for the build.

nanguantong commented 1 year ago

You're still going to need to specify a preloadpath for the build.

add preloadpath = {".", "dir1", "dir2"},

not work yet.

nanguantong commented 1 year ago

Could you please try it out at your local machine? @saudet