Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symbol not found error integrating BASS audio library with ffigen #220

Closed
JimTompkins opened this issue Sep 23, 2022 · 3 comments
Closed

Comments

@JimTompkins
Copy link

I'm trying to integrate the BASS audio dynamic library for iOS from un4seen Developments with Flutter. I've started a Flutter FFI plugin that can be found here. It uses ffigen to convert the bass.h file to generated_bindings.dart.

Here is a snippet from generated_bindings.dart:

  int BASS_Init(
    int device,
    int freq,
    int flags,
    ffi.Pointer<ffi.Void> win,
    ffi.Pointer<ffi.Void> dsguid,
  ) {
    return _BASS_Init(
      device,
      freq,
      flags,
      win,
      dsguid,
    );
  }

  late final _BASS_InitPtr = _lookup<
      ffi.NativeFunction<
          BOOL Function(ffi.Int32, DWORD, DWORD, ffi.Pointer<ffi.Void>,
              ffi.Pointer<ffi.Void>)>>('_BASS_Init');
  late final _BASS_Init = _BASS_InitPtr.asFunction<
      int Function(
          int, int, int, ffi.Pointer<ffi.Void>, ffi.Pointer<ffi.Void>)>();

It builds (Flutter 3.3, XCode 14, ffigen 6.1.2) 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 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.

Any comments/suggestions greatly appreciated!

@dcharkes
Copy link
Collaborator

dcharkes commented Sep 23, 2022

I have a setup locally with xcframeworks

ios/mylib_staticlib.podspec:

  s.pod_target_xcconfig = {
    'DEFINES_MODULE' => 'YES',
    'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386',
    "OTHER_LDFLAGS[sdk=iphoneos*]" => "-force_load $(PODS_TARGET_SRCROOT)/Frameworks/mylib_staticlib.xcframework/ios-arm64_armv7/libmylib_staticlib.a",
    "OTHER_LDFLAGS[sdk=iphonesimulator*]" => "-force_load $(PODS_TARGET_SRCROOT)/Frameworks/mylib_staticlib.xcframework/ios-arm64_x86_64-simulator/libmylib_staticlib.a",
  }
  s.vendored_frameworks = 'Frameworks/mylib_staticlib.xcframework'
  s.swift_version = '5.0'

ios/Classes/dummy_file.c

// A dummy file so that the mylib_staticlib.framework is created.

.a files should work as well, but then the podspec is:

s.pod_target_xcconfig = {
--
  | 'DEFINES_MODULE' => 'YES',
  | 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64',
  | "OTHER_LDFLAGS" => "-force_load $(PODS_TARGET_SRCROOT)/Frameworks/libmylib_staticlib.a"
  | }
  | s.vendored_libraries = 'Frameworks/libmylib_staticlib.a'

Other things to double check:

  • Is the .a file for the right architecture?

P.S. This is not an ffigen issue, the bindings are not wrong.
This is a question with Flutter FFI plugins, and belongs on the Flutter repo (or StackOverflow).

@JimTompkins
Copy link
Author

Thanks for that hint! I'm trying to use a static library, so I tried adding these two lines to my podspec file:

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'

but I get a file not found error:

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

But the .a file is at that location:

% 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

Apologies for what feels like a newbie question now...

Thanks!

@JimTompkins
Copy link
Author

Found that the ( ) around $SRCROOT in the -force_load were causing the problem.

@liamappelbe liamappelbe transferred this issue from dart-lang/ffigen Nov 15, 2023
HosseinYousefi pushed a commit that referenced this issue Nov 16, 2023
* Move summarizer invocation into summary.dart for better testability.
* Support reading source JARs (#208)
* Fix an issue where the summarizer failed when providing only classes and no source (#147)
HosseinYousefi pushed a commit that referenced this issue Nov 16, 2023
* Move summarizer invocation into summary.dart for better testability.
* Support reading source JARs (#208)
* Fix an issue where the summarizer failed when providing only classes and no source (#147)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants