@@ -16,9 +16,7 @@ type Options struct {
1616}
1717
1818func Defaults () * Options {
19- libraryDirDefault := "/usr/lib"
20- libraryNameDefault := "libonnxruntime.so"
21- libraryPathDefault := fileutil .PathJoinSafe (libraryDirDefault , libraryNameDefault )
19+ _ , libraryDirDefault , libraryPathDefault := getDefaultLibraryPaths ()
2220 return & Options {
2321 ORTOptions : & OrtOptions {
2422 LibraryDir : & libraryDirDefault ,
@@ -31,6 +29,17 @@ func Defaults() *Options {
3129 }
3230}
3331
32+ func getDefaultLibraryPaths () (string , string , string ) {
33+ switch runtime .GOOS {
34+ case "windows" :
35+ return `onnxruntime.dll` , `.\` , `.\onnxuntime.dll`
36+ case "darwin" :
37+ return "libonnxruntime.dylib" , "/usr/local/lib" , "/usr/local/lib/libonnxruntime.dylib"
38+ default :
39+ return "libonnxruntime.so" , "/usr/lib" , "/usr/lib/libonnxruntime.so"
40+ }
41+ }
42+
3443type OrtOptions struct {
3544 LibraryPath * string
3645 LibraryDir * string
@@ -70,23 +79,14 @@ func WithOnnxLibraryPath(ortLibraryPath string) WithOption {
7079 return fmt .Errorf ("%s is not a directory" , ortLibraryPath )
7180 }
7281
73- var libraryFileName string
74- switch runtime .GOOS {
75- case "windows" :
76- libraryFileName = "onnxruntime.dll"
77- case "darwin" :
78- libraryFileName = "libonnxruntime.dylib"
79- case "linux" :
80- libraryFileName = "libonnxruntime.so"
81- }
82-
83- ortLibraryFullPath := fileutil .PathJoinSafe (ortLibraryPath , libraryFileName )
82+ libraryName , _ , _ := getDefaultLibraryPaths ()
83+ ortLibraryFullPath := fileutil .PathJoinSafe (ortLibraryPath , libraryName )
8484 exists , err := fileutil .FileExists (ortLibraryPath )
8585 if err != nil {
8686 return fmt .Errorf ("error checking for existence of ONNX Runtime library file: %w" , err )
8787 }
8888 if ! exists {
89- return fmt .Errorf ("ONNX Runtime library does not exist at %q" , ortLibraryPath )
89+ return fmt .Errorf ("ONNX Runtime library %s does not exist at %q" , libraryName , ortLibraryPath )
9090 }
9191 o .ORTOptions .LibraryPath = & ortLibraryFullPath
9292 o .ORTOptions .LibraryDir = & ortLibraryPath
0 commit comments