Author Topic: Integrating BASS with Flutter: symbol not found error  (Read 452 times)

jimtompkins

  • Posts: 15
I'm trying to integrate BASS with Flutter, Google's cross-platform app development environment.  I've started a Flutter plugin that can be found here: https://github.com/JimTompkins/flutter_bass.  It uses Flutter's FFI (foreign function interface) mechanism and a package called ffigen to convert the bass.h file to generated_bindings.dart.

It builds (Flutter 3.3, XCode 13) but throws a run-time error when I try to call the BASS_init function:
Failed to lookup symbol '_BASS_Init': dlsym(0x100f61e18, _BASS_Init): symbol not found

I can see the symbol in the libbass.a file using nm -gU libbass.a

I suspect this is more a Flutter problem than a BASS problem, but I thought there might be others interested in trying to use BASS with Flutter.

Any comments/suggestions welcomed!

jimtompkins

  • Posts: 15
I added the following frameworks to the Xcode build:
    AVFoundation, AudioToolbox, SystemConfiguration, CFNetwork, Accelerate
In Xcode by going to Build Phase-->Link Binary with Libraries-->Add
This did not make any difference i.e. still getting symbol error

I checked that “Enable bitcode” is set to “No” in Xcode under Build SettingsBuild Options.

The search continues...

Ian @ un4seen

  • Administrator
  • Posts: 25446
I'm not familiar with Flutter, so unfortunately I'm unable to help with that, but from the mention of libbass.a it looks like you're building for iOS. If so, perhaps you would have more luck with a dynamic library? The iOS libraries will be switching from static to dynamic at the next BASS release, and here's a dynamic build that you can try already now:

   www.un4seen.com/stuff/bass-ios-test.zip

jimtompkins

  • Posts: 15
Thanks, yes, I'm targeting iOS so will try the link.

jimtompkins

  • Posts: 15
I got a hint from this Github issue https://github.com/dart-lang/ffigen/issues/458 post: use a force_load option to Xcode in the podspec file:

Code: [Select]
s.pod_target_xcconfig = {'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386', "OTHER_LDFLAGS" => '-force_load ($SRCROOT)/../../../ios/bass24-ios/bass.xcframework/ios-arm64_armv7_armv7s/libbass.a' } s.vendored_libraries = '($SRCROOT)/../../../ios/bass24-ios/bass.xcframework/ios-arm64_armv7_armv7s/libbass.a'
I tried this but now I'm getting a file not found error.

Code: [Select]
Could not build the precompiled application for the device.

Error (Xcode): File not found:

(/Users/jimtompkins/git/flutter_bass/example/ios/Pods)/../../../ios/bass24-ios/bass.xcframework/ios-arm64_armv7_armv7s/libbass.a

I checked and the file is there:

Code: [Select]
% ls -als /Users/jimtompkins/git/flutter_bass/example/ios/Pods/../../../ios/bass24-ios/bass.xcframework/ios-arm64_armv7_armv7s/libbass.a                                     


1536 -rw-r--r--@ 1 jimtompkins  staff  785096  8 Sep  2021 /Users/jimtompkins/git/flutter_bass/example/ios/Pods/../../../ios/bass24-ios/bass.xcframework/ios-arm64_armv7_armv7s/libbass.a

Any hints greatly appreciated!


Ian @ un4seen

  • Administrator
  • Posts: 25446
I got a hint from this Github issue https://github.com/dart-lang/ffigen/issues/458 post: use a force_load option to Xcode in the podspec file:

Code: [Select]
s.pod_target_xcconfig = {'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386', "OTHER_LDFLAGS" => '-force_load ($SRCROOT)/../../../ios/bass24-ios/bass.xcframework/ios-arm64_armv7_armv7s/libbass.a' } s.vendored_libraries = '($SRCROOT)/../../../ios/bass24-ios/bass.xcframework/ios-arm64_armv7_armv7s/libbass.a'
I tried this but now I'm getting a file not found error.

Code: [Select]
Could not build the precompiled application for the device.

Error (Xcode): File not found:

(/Users/jimtompkins/git/flutter_bass/example/ios/Pods)/../../../ios/bass24-ios/bass.xcframework/ios-arm64_armv7_armv7s/libbass.a

Those brackets in the filename look like a problem, and they seem to be coming from the OTHER_LDFLAGS setting. What happens if you remove them from there, ie. "-force_load $SRCROOT/...".

jimtompkins

  • Posts: 15
Thanks Ian!  That was definitely needed. 

Then I also had to add these frameworks to the podspec file:
AudioTookbox, CFNetwork, AVFoundation, JavaScriptCore and Accelerate, even though these we set in Xcode.

I've updated the Github repo so other can hopefully use this to get started with BASS in Flutter.

Ian @ un4seen

  • Administrator
  • Posts: 25446
Excellent!

Were you also able to get it working with the dynamic libraries that I posted above? I guess it'll need to be done a bit differently then, as I believe the "force_load" option applies to static libraries. I found this on the subject:

   https://stackoverflow.com/questions/69214595/how-to-manually-add-a-xcframework-to-a-flutter-ios-plugin