hey guys, I am trying to build a framework from a ...
# kotlin-native
c
hey guys, I am trying to build a framework from a cinterops that imports another framweork: NearbyMessages from Google So I install the NearbyMessages framework via cocoapods. NO issues. I defined my cinterops bloc and I can use the generated bindings in Kotlin classes. I can also publish locally my multiplatform library. But if I decide to export my ios target as a framework, I receive this error:
ld: symbol(s) not found for architecture arm64
this only appears because I added
staticLibraries
and a
libraryPaths
in my def file since I noticed that the google framework contains a native library
.a
and other frameworks as part of the its internal dependency. I have tried multiple combination of using
linkerOpts
with
-L
or
-F
pointing at the folder where the framework has been imported but nothing works. I have not been able to find a clear explanation as to how to create correct cinterops with ios framework that contains a static library and multiple indirect dependencies since I suspect that the impossibility to export this as ios framework is related to my wrong configuration of the cinterops. Thanks in advance Def File:
Copy code
depends = Foundation
language = Objective-C
headers = GNSMessages.h
staticLibraries = NearbyMessages/Libraries/libGNSMessages.a
libraryPaths = /Users/cyrille.quemin/Documents/git/multiplatform-p2p/p2p-common/src/iosMain/dependencies/Pods
Cinterops:
Copy code
binaries {
                framework("p2p_common") {
                    linkerOpts "-L${podsDir}/NearbyMessages/Libraries"
                }
            }
            compilations.main.cinterops {
                NearbyMessage {
                    defFile "src/iOSMain/c_interop/NearbyMessages.def"
                    includeDirs "${podsDir}/Headers/Public/NearbyMessages"
                    linkerOpts "-F${podsDir}/NearbyMessages/Libraries/"
              }
         }
s
ld: symbol(s) not found for architecture arm64
Is it possible that you have added only simulator variant of static library?
linkerOpts “-F${podsDir}/NearbyMessages/Libraries/”
This line should be moved under
framework {
.
c
I also tried with with
preset.iosX64
, and to move the line under
framework
like you suggested, but still get the same error at the linking phase :
linkP2p_commonDebugFrameworkIOS
s
Could you post the complete error message here?
c
Copy code
> Task :p2p-common:linkP2p_commonDebugFrameworkIOS
ld: warning: ignoring file /Users/cyrille.quemin/Documents/git/multiplatform-p2p/p2p-common/src/iOSMain/Libraries/CryptoCocoa.framework/CryptoCocoa, missing required architecture x86_64 in file /Users/cyrille.quemin/Documents/git/multiplatform-p2p/p2p-common/src/iOSMain/Libraries/CryptoCocoa.framework/CryptoCocoa (2 slices)
ld: warning: could not create compact unwind for _ffi_call_unix64: does not use RBP or RSP based frame
Undefined symbols for architecture x86_64:
  "_AVAudioSessionCategoryPlayAndRecord", referenced from:
      l069 in libGNSMessages.a(GNSAudioModem.o)
  "_AVAudioSessionInterruptionNotification", referenced from:
      l018 in libGNSMessages.a(GCPAudioTokenStrategy.o)
      l019 in libGNSMessages.a(GCPAudioTokenStrategy.o)
  "_AVAudioSessionInterruptionTypeKey", referenced from:
      l098 in libGNSMessages.a(GCPAudioTokenStrategy.o)
  "_AVAudioSessionRouteChangeNotification", referenced from:
      l004 in libGNSMessages.a(GNSAudioPlayer.o)
  "_AudioQueueAllocateBuffer", referenced from:
      l009 in libGNSMessages.a(GNSAudioPlayer.o)
      l038 in libGNSMessages.a(GNSAudioRecorder.o)
  "_AudioQueueDispose", referenced from:
      l005 in libGNSMessages.a(GNSAudioPlayer.o)
      l024 in libGNSMessages.a(GNSAudioRecorder.o)
[...]
      l005 in libGNSMessages.a(GNSImage.o)
  "_UIGraphicsBeginImageContextWithOptions", referenced from:
      l005 in libGNSMessages.a(GNSImage.o)
  "_UIGraphicsEndImageContext", referenced from:
      l005 in libGNSMessages.a(GNSImage.o)
  "_UIGraphicsGetCurrentContext", referenced from:
      l005 in libGNSMessages.a(GNSImage.o)
  "_UIGraphicsGetImageFromCurrentImageContext", referenced from:
      l005 in libGNSMessages.a(GNSImage.o)
  "_vDSP_vflt16", referenced from:
      l026 in libGNSMessages.a(GNSAudioRecorder.o)
ld: symbol(s) not found for architecture x86_64
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld invocation reported errors
I remove about 200 lines of detail of what is not found.you can ignore the lines about cryptoCocoa not built for x86
s
Copy code
Undefined symbols for architecture x86_64:
  "_AVAudioSessionCategoryPlayAndRecord", referenced from:
      l069 in libGNSMessages.a(GNSAudioModem.o)
This error means that
libGNSMessages.a
depends on AVFoundation, so you should include
-framework AVFoundation
to your linker options too.
c
Yes that worked, it removed the line about _AVxxxx
do I have to search for every single error on internet and try to link with the right framework? Is there an efficient way to do this?
s
It is enough to search for the name that is not found, with leading underscore removed. Apple documentation is likely to be found this way, and it contains the information about system framework to be linked.
c
I will try that, thnanks a lot
Do you know how to specify non Apple framework with the
-framework
option? It work fine with Apple framework but I need to add some framework that are not from Apple. I tried relative paths, absolute paths and I keep on having:
ld: framework not found GoogleInterchangeUtilities
where this displays the argument I put after
-framework
option
it is ok I found it
linkerOpts = -framework AVFoundation -F path/to/my/framework/folder -framework MyFramework
works