Gets you the path to the executable - the item you double-click to run the app. The .exe on wondows, the .app on macOS, and the executable file on Linux.
@executable_path does work. It’s used in my WeatherKit and macOS toolbar products, but keep in mind that its use differs between macOS and iOS. On macOS, the app bundle contains a MacOS folder which contains the app binary and a Frameworks folder which contains the frameworks, like this:
Contents
MacOS
AppName
Frameworks
Lib.dylib
And the path for accessing a dylib should be
@executable_path/../Frameworks/Lib.dylib
On iOS, the app is at the top level like this:
Contents
AppName
Frameworks
Lib.dylib
And so the path needs to be written as:
@executable_path/Frameworks/Lib.dylib
It’s also important to remember that in some cases these folder names are case-sensitive, so it’s always important to match what’s in the bundle.
I’m also going to point out that if you’re accessing a custom framework, you can’t just point to it in a declare and expect it to be loaded. For that, you also need to use a call to dlopen:
Public Function LoadLibrary(frameworkName as string) As Boolean
// Loads the multipeer framework for use by your app
#If TargetMacOS Or TargetIOS
// Make sure you add a copy files step to copy your library to the Frameworks folder
Declare Function dlopen Lib "/usr/lib/libSystem.dylib" (name As CString, flags As Int32) As Ptr
Dim p As ptr
#If TargetIOS
p = dlopen("@executable_path/Frameworks/" + frameworkName + ".framework/" + frameworkName + "", 13)
#ElseIf TargetMacOS
p = dlopen("@executable_path/../frameworks/" + frameworkName + ".framework/" + frameworkName + "", 13)
#EndIf
If p=Nil Then
Declare Function dlerror Lib "/usr/Lib/libSystem.dylib" () As CString
Dim reason As String = dlerror()
Raise New RuntimeException(reason)
End If
Return p<>Nil
#EndIf
Return False
End Function