Recent

Author Topic: Loading libbass.dylib via application bundle fails  (Read 2725 times)

stem

  • Jr. Member
  • **
  • Posts: 84
Loading libbass.dylib via application bundle fails
« on: November 12, 2021, 09:35:06 pm »
Hi,

unfortunately I don't succeed in loading libbass.dylib via the Frameworks
directory in my application bundle.

Code: Pascal  [Select][+][-]
  1. BASS_Handle := LoadLibrary(PChar('libbass.dylib'));

BASS_Handle equals 0.

I've made everything as it is explained in
https://wiki.lazarus.freepascal.org/macOS_Dynamic_Libraries

Does anyone have hints for me?

Can I check in what places the application (bundle) is searching for the dynamic library?

Thank you.

stem

winni

  • Hero Member
  • *****
  • Posts: 3045
Re: Loading libbass.dylib via application bundle fails
« Reply #1 on: November 12, 2021, 09:46:40 pm »
Hi!

un4seen has a forum for BASS with a lot of knowledge like here:

http://www.un4seen.com/forum/?topic=17383.0

Winni
« Last Edit: November 12, 2021, 09:50:11 pm by winni »

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1963
  • Former Delphi 1-7, 10.2 user
Re: Loading libbass.dylib via application bundle fails
« Reply #2 on: November 13, 2021, 12:40:29 am »
I've made everything as it is explained in
https://wiki.lazarus.freepascal.org/macOS_Dynamic_Libraries

Does anyone have hints for me?

Are you sure you set the path to the library in the executable as I detailed in the article at Additional steps using a Lazarus project ?

Quote
Can I check in what places the application (bundle) is searching for the dynamic library?

Have you tried the various methods listed in that article in the section entitled Observe the dynamic linker in action especially using dtruss?
 
Lazarus 2.3, FPC 3.3.1 macOS 12.3.1 x86_64 Xcode 13.3.1
Lazarus 2.3, FPC 3.3.1 macOS 12.3.1 aarch64 Xcode 13.3.1

stem

  • Jr. Member
  • **
  • Posts: 84
Re: Loading libbass.dylib via application bundle fails
« Reply #3 on: November 13, 2021, 04:06:20 pm »
Yes, I've read the article before.  :) Thank you for the documentation, I appreciate it a lot!

dtruss says:

Code: [Select]
stat64("/Volumes/xyz/binaries/macos/myapp.app/Contents/MacOS/../Frameworks/libbass.dylib\0", 0x7FFEE7BF2B60, 0x0) = 0 0
stat64("/Volumes/xyz/binaries/macos/myapp.app/Contents/MacOS/../Frameworks/libbass.dylib\0", 0x7FFEE7BF2FE0, 0x0) = 0 0
open("/Volumes/xyz/binaries/macos/myapp.app/Contents/MacOS/../Frameworks/libbass.dylib\0", 0x0, 0x0) = 3 fcntl0
dtrace: error on enabled probe ID 2201 (ID 465: syscall::pread:return): invalid kernel access in action #12 at DIF offset 20
dtrace: error on enabled probe ID 2201 (ID 465: syscall::pread:return): invalid kernel access in action #12 at DIF offset 20

The executable seems to search for the dynamic library in the correct folder. But I'm not sure, if the last two lines have anything to do with my problem.

Thank you!

stem

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1963
  • Former Delphi 1-7, 10.2 user
Re: Loading libbass.dylib via application bundle fails
« Reply #4 on: November 14, 2021, 01:23:19 am »
What's the error message? I assume you have the handle failure code similar to this from my article:

Code: Pascal  [Select][+][-]
  1. else
  2.     // error message on load failure
  3.     ShowMessage('GetLastOSError2 = ' + SysErrorMessage(GetLastOSError));

The open() return code for the library is successful. I'm not sure why it fails to get a handle... is the library bitness correct? 64 bit?

What does file /Volumes/xyz/binaries/macos/myapp.app/Contents/MacOS/../Frameworks/libbass.dylib. return?

I don't think the last two lines are related, just macOS security blocking some dtruss kernel probes.
« Last Edit: November 14, 2021, 01:26:31 am by trev »
Lazarus 2.3, FPC 3.3.1 macOS 12.3.1 x86_64 Xcode 13.3.1
Lazarus 2.3, FPC 3.3.1 macOS 12.3.1 aarch64 Xcode 13.3.1

stem

  • Jr. Member
  • **
  • Posts: 84
Re: Loading libbass.dylib via application bundle fails
« Reply #5 on: November 14, 2021, 01:38:16 pm »
I've found out that the problem is that the following variable is nil:

Code: Pascal  [Select][+][-]
  1. @BASS_SetConfig:= GetProcAddress(BASS_Handle, PChar('BASS_SetConfig'));

(which obviously means that this function is not correctly linked in)

The error message is "operation not supported".

I'm trying to find the error. (The same code and the library works perfectly with Windows and Linux.)

P.S.

Code: [Select]
file /Volumes/xyz/binaries/macOS/myapp.app/Contents/MacOS/../Frameworks/libbass.dylib

/Volumes/xyz/binaries/macOS/myapp.app/Contents/MacOS/../Frameworks/libbass.dylib: Mach-O universal binary with 3 architectures: [x86_64:Mach-O 64-bit dynamically linked shared library x86_64] [i386:Mach-O dynamically linked shared library i386] [arm64:Mach-O 64-bit dynamically linked shared library arm64]
/Volumes/xyz/binaries/macOS/myapp.app/Contents/MacOS/../Frameworks/libbass.dylib (for architecture x86_64): Mach-O 64-bit dynamically linked shared library x86_64
/Volumes/xyz/binaries/macOS/myapp.app/Contents/MacOS/../Frameworks/libbass.dylib (for architecture i386): Mach-O dynamically linked shared library i386
/Volumes/xyz/binaries/macOS/myapp.app/Contents/MacOS/../Frameworks/libbass.dylib (for architecture arm64): Mach-O 64-bit dynamically linked shared library arm64



stem
« Last Edit: November 14, 2021, 02:12:59 pm by stem »

stem

  • Jr. Member
  • **
  • Posts: 84
Re: Loading libbass.dylib via application bundle fails
« Reply #6 on: November 14, 2021, 02:25:02 pm »
I've solved the problem by changing

Code: Pascal  [Select][+][-]
  1. BASS_Handle : Thandle = 0;

to

Code: Pascal  [Select][+][-]
  1. BASS_Handle : TLibHandle = 0;

in the file Dynamic_Bass.pas that can be downloaded on the homepage of the project.

 :)

Thank you.

stem

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1963
  • Former Delphi 1-7, 10.2 user
Re: Loading libbass.dylib via application bundle fails
« Reply #7 on: November 14, 2021, 10:06:51 pm »
My Wiki examples use TLibHandle <phew/> - just another reminder that macOS is not Windows nor Linux :)

Thanks for returning with the solution... many don't.
Lazarus 2.3, FPC 3.3.1 macOS 12.3.1 x86_64 Xcode 13.3.1
Lazarus 2.3, FPC 3.3.1 macOS 12.3.1 aarch64 Xcode 13.3.1

 

TinyPortal © 2005-2018