@@ -47,26 +47,57 @@ public synchronized static void loadNative() throws IOException {
4747 String os = System .getProperty ("os.name" );
4848 String arch = System .getProperty ("os.arch" , "generic" ).toLowerCase (Locale .ENGLISH );
4949 if (os .startsWith ("Linux" ) || os .startsWith ("LINUX" )) {
50- if (arch .startsWith ("amd64" ) || arch .startsWith ("x86_64" )) {
51- loadNative ("linux/x86_64/lib_lightgbm.so" , "lib_lightgbm.so" );
52- loadNative ("linux/x86_64/lib_lightgbm_swig.so" , "lib_lightgbm_swig.so" );
53- nativeLoaded = true ;
54- } else if (arch .startsWith ("aarch64" ) || arch .startsWith ("arm64" )) {
55- loadNative ("linux/aarch64/lib_lightgbm.so" , "lib_lightgbm.so" );
56- loadNative ("linux/aarch64/lib_lightgbm_swig.so" , "lib_lightgbm_swig.so" );
57- nativeLoaded = true ;
50+ try {
51+ if (arch .startsWith ("amd64" ) || arch .startsWith ("x86_64" )) {
52+ loadNative ("linux/x86_64/lib_lightgbm.so" , "lib_lightgbm.so" );
53+ loadNative ("linux/x86_64/lib_lightgbm_swig.so" , "lib_lightgbm_swig.so" );
54+ nativeLoaded = true ;
55+ } else if (arch .startsWith ("aarch64" ) || arch .startsWith ("arm64" )) {
56+ loadNative ("linux/aarch64/lib_lightgbm.so" , "lib_lightgbm.so" );
57+ loadNative ("linux/aarch64/lib_lightgbm_swig.so" , "lib_lightgbm_swig.so" );
58+ nativeLoaded = true ;
59+ }
60+ } catch (UnsatisfiedLinkError err ) {
61+ String message = err .getMessage ();
62+ if (message .contains ("libgomp" )) {
63+ System .out .println ("\n \n \n " );
64+ System .out .println ("****************************************************" );
65+ System .out .println ("Your Linux system probably has no 'libgomp' library installed!" );
66+ System .out .println ("Please double-check the lightgbm4j install instructions:" );
67+ System .out .println ("- https://github.com/metarank/lightgbm4j/" );
68+ System .out .println ("- or just install the libgomp with your package manager" );
69+ System .out .println ("****************************************************" );
70+ System .out .println ("\n \n \n " );
71+ }
5872 }
5973 } else if (os .startsWith ("Mac" )) {
60- if (arch .startsWith ("amd64" ) || arch .startsWith ("x86_64" )) {
61- loadNative ("osx/x86_64/lib_lightgbm.dylib" , "lib_lightgbm.dylib" );
62- loadNative ("osx/x86_64/lib_lightgbm_swig.dylib" , "lib_lightgbm_swig.dylib" );
63- nativeLoaded = true ;
64- } else if (arch .startsWith ("aarch64" ) || arch .startsWith ("arm64" )) {
65- loadNative ("osx/aarch64/lib_lightgbm.dylib" , "lib_lightgbm.dylib" );
66- loadNative ("osx/aarch64/lib_lightgbm_swig.dylib" , "lib_lightgbm_swig.dylib" );
67- nativeLoaded = true ;
68- } else {
69- System .out .println ("arch " + arch + " is not supported" );
74+ try {
75+ if (arch .startsWith ("amd64" ) || arch .startsWith ("x86_64" )) {
76+ loadNative ("osx/x86_64/lib_lightgbm.dylib" , "lib_lightgbm.dylib" );
77+ loadNative ("osx/x86_64/lib_lightgbm_swig.dylib" , "lib_lightgbm_swig.dylib" );
78+ nativeLoaded = true ;
79+ } else if (arch .startsWith ("aarch64" ) || arch .startsWith ("arm64" )) {
80+ loadNative ("osx/aarch64/lib_lightgbm.dylib" , "lib_lightgbm.dylib" );
81+ loadNative ("osx/aarch64/lib_lightgbm_swig.dylib" , "lib_lightgbm_swig.dylib" );
82+ nativeLoaded = true ;
83+ } else {
84+ System .out .println ("arch " + arch + " is not supported" );
85+ throw new UnsatisfiedLinkError ("no native lightgbm library found for your OS " +os );
86+ }
87+ } catch (UnsatisfiedLinkError err ) {
88+ String message = err .getMessage ();
89+ if (message .contains ("libomp.dylib" )) {
90+ System .out .println ("\n \n \n " );
91+ System .out .println ("****************************************************" );
92+ System .out .println ("Your MacOS system probably has no 'libomp' library installed!" );
93+ System .out .println ("Please double-check the lightgbm4j install instructions:" );
94+ System .out .println ("- https://github.com/metarank/lightgbm4j/" );
95+ System .out .println ("- or just do 'brew install libomp'" );
96+ System .out .println ("****************************************************" );
97+ System .out .println ("\n \n \n " );
98+
99+ }
100+ throw err ;
70101 }
71102 } else if (os .startsWith ("Windows" )) {
72103 loadNative ("windows/x86_64/lib_lightgbm.dll" , "lib_lightgbm.dll" );
@@ -78,7 +109,7 @@ public synchronized static void loadNative() throws IOException {
78109 }
79110 }
80111
81- private static void loadNative (String path , String name ) throws IOException {
112+ private static void loadNative (String path , String name ) throws IOException , UnsatisfiedLinkError {
82113 System .out .println ("Loading native lib " + path );
83114 String tmp = System .getProperty ("java.io.tmpdir" );
84115 File libFile = new File (tmp + File .separator + name );
@@ -91,7 +122,8 @@ private static void loadNative(String path, String name) throws IOException {
91122 try {
92123 System .load (libFile .toString ());
93124 } catch (UnsatisfiedLinkError err ) {
94- System .out .println ("Cannot load library: " + err + " cause: " + err .getMessage ());
125+ System .out .println ("Cannot load library:" + err .getMessage ());
126+ throw err ;
95127 }
96128 }
97129
0 commit comments