Internet app - OpenLibrary(dylib) returns 0

Mac OSX specific forum
Offin
User
User
Posts: 34
Joined: Mon May 04, 2009 10:53 am
Location: France

Internet app - OpenLibrary(dylib) returns 0

Post by Offin »

Hello,

My software contains a binary file (.app) and a library file (.dylib).
Both are compiled with PB 5.73.
They are signed (with hardened runtime option).
A DMG is made with these files.
The DMG is signed and notarized (with my Apple ID developper)
No problem until now.
The DMG is uploaded on internet.
I download the DMG from internet.
I extract the folder with the app & dylib files.

When i run the app file, there is the following error message "error loading library 'xxx.dylib !' (means "OpenLibrary() returns 0)'.

Does somebody know what i am missing ?


Some remarks

If i import the same DMG file from my local network (not internet), there is no problem.

The signature check for the dylib file command shows: "Info.plist=not bound".
But in my opinion, it is not possible to embeed a plist file with a dylib file.

The notarization procedure shows this message:
2020-12-04 10:30:41.505 altool[4134:88747] CFURLRequestSetHTTPCookieStorageAcceptPolicy_block_invoke: no longer implemented and should not be called
No errors uploading 'xxxxx.dmg'.
RequestUUID = 16f31155-3115-4468-930e-c0446828b706
But i think this is just a warning not important because the app file works correctly when it is packaged without the dylib file.
Last edited by Offin on Fri Dec 04, 2020 8:24 pm, edited 5 times in total.
User avatar
mk-soft
Always Here
Always Here
Posts: 5334
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Error loading library 'xxx.dylib' !

Post by mk-soft »

Where do you put the DyLib?

It is best to put the own library into the APP package. "MyApp.app/Contents/Library" or "MyApp.app/Contents/Resources".
For this I have written a tool for PB-IDE.

Link: PB-IDE Tool MyAppData
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Offin
User
User
Posts: 34
Joined: Mon May 04, 2009 10:53 am
Location: France

Re: Error loading library 'xxx.dylib' !

Post by Offin »

The dylib is presently at same level than the app file/folder.
We were a bit lazy to do this change.
But this time we may not have other choice with the recent new OS "Big Sur".

We will work on that.

Thank you for your answer.
Offin
User
User
Posts: 34
Joined: Mon May 04, 2009 10:53 am
Location: France

Re: Internet app - OpenLibrary(...dylib) returns 0

Post by Offin »

We made an APP package with all files (including the dylib file) into the folder "OurProgram.app/Contents/".
But still same problem: the function OpenLibrary(#PB_Any, "OurPBLibrary.dylib") in the app returns 0.

May be some keys to add in the plist file ?

PS: any example of an app with a PB dylib in would be welcome.
User avatar
mk-soft
Always Here
Always Here
Posts: 5334
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Internet app - OpenLibrary(dylib) returns 0

Post by mk-soft »

The entire path to the library must be specified.

also copy the library into the App folder Contents/Resources or Contents/Library. Order must be.
Remember: PB-IDE Tool MyAppData

Even if I haven't installed Big Sur yet, it has to be done this way.

Code: Select all

libpath.s = GetLibraryPath() + "OurPBLibrary.dylib"
Debug libpath
lib = OpenLibrary(#PB_Any, libpath)
PathHelper

Code: Select all

;- TOP

; Comment: PathHelper v1.01 by mk-soft

Macro GetParentPath(Path)
  GetPathPart(RTrim(Path, #PS$))
EndMacro

Procedure.s GetProgramPath()
  Protected r1.s
  r1 = GetPathPart(ProgramFilename())
  CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
    r1 = GetParentPath(r1)
    r1 = GetParentPath(r1)
  CompilerEndIf
  ProcedureReturn r1
EndProcedure

Procedure.s GetResourcesPath()
  Protected r1.s
  r1 = GetPathPart(ProgramFilename())
  CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
    r1 = GetParentPath(r1)
  CompilerEndIf
  r1 + "Resources" + #PS$
  ProcedureReturn r1
EndProcedure

Procedure.s GetLibraryPath()
  Protected r1.s
  r1 = GetPathPart(ProgramFilename())
  CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
    r1 = GetParentPath(r1)
  CompilerEndIf
  r1 + "Library" + #PS$
  ProcedureReturn r1
EndProcedure

CompilerIf #PB_Compiler_IsMainFile
  Debug GetProgramPath()
  Debug GetResourcesPath()
  Debug GetLibraryPath()
CompilerEndIf
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1243
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: Internet app - OpenLibrary(dylib) returns 0

Post by Paul »

I've always used
OpenLibrary(#PB_Any, "mylib.dylib")

and simply placed the .dylib file in myapp.app\Contents\
next to Info.plist and it just works ;)


Has Apple broken all backward compatibility with the latest OS update ?
Image Image
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1243
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: Internet app - OpenLibrary(...dylib) returns 0

Post by Paul »

Offin wrote: PS: any example of an app with a PB dylib in would be welcome.
You can see if this works...
https://reelmedia.org/test/testdll.zip

It contains 2 PB files that were used to make the compiled app and the compiled file to test with.
Running the app should return MessageBox containing "SUM" "10"

Works here on MacOS 10.12, 10.14, 10.15 (I don't have anything higher)
Image Image
Mindphazer
Enthusiast
Enthusiast
Posts: 340
Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie

Re: Internet app - OpenLibrary(dylib) returns 0

Post by Mindphazer »

Works here, i'm on Big Sur and PB 5.73
Launching the app returns the messagebox
MacBook Pro 14" M1 Pro - 16 Gb - MacOS 14 - Iphone 15 Pro Max - iPad at home
...and unfortunately... Windows at work...
Offin
User
User
Posts: 34
Joined: Mon May 04, 2009 10:53 am
Location: France

Re: Internet app - OpenLibrary(dylib) returns 0

Post by Offin »

@ mk-soft
Thank you very much for this code.
It works now.

FYI, we were using a relative path to load the library, and it does not work with Big Sur.
It is now ok with an absolute path, whatever is the library location (in folder "library" or at "app" folder level).

Thank you all for your precious help.
Post Reply