title: Using a static iOS library in a NativeScript 5.4 plugin
body: <p>NativeScript 5.4.2</p>
  
  <p>tns-core-modules 5.4.3</p>
  
  <p>tns-ios 5.4.2</p>
  
  <p>Xcode 10.2.1</p>
  
  <p>I am attempting to create a plugin for this background geolocation library for iOS: <a href="https://github.com/Yermo/background-geolocation-ios" rel="nofollow noreferrer">https://github.com/Yermo/background-geolocation-ios</a></p>
  
  <p>The project produces a static library, libBackgroundGeolocation.a. </p>
  
  <p>I have read the documentation on how to use a static iOS library: <a href="https://docs.nativescript.org/plugins/Use-Native-iOS-Libraries#static-libraries" rel="nofollow noreferrer">https://docs.nativescript.org/plugins/Use-Native-iOS-Libraries#static-libraries</a></p>
  
  <p>I have read about the required directory structure: <a href="https://docs.nativescript.org/plugins/plugin-reference#directory-structure" rel="nofollow noreferrer">https://docs.nativescript.org/plugins/plugin-reference#directory-structure</a></p>
  
  <p>My plugin is based on the official plugin seed, so I have a demo directory and a src directory containing my plugin code and a platforms/ios directory under that.</p>
  
  <p>I have copied the BackgroundGeolocation.a file into src/platforms/ios.</p>
  
  <p>I have created a src/platforms/ios/include/BackgroundGeolocation directory and copied the public header files from the project into that directory. </p>
  
  <p>I notice that src/platforms/ios/include/BackgroundGeolocation/module.modulemap file has been created. </p>
  
  <p>In the plugin directory I can successfully run 'npm run build'. </p>
  
  <p>However, from the demo directory if I run 'tns build ios' I consistently get a "ld: Library not found for -lBackgroundGeolocation" error.</p>
  
  <p>If I rename the library to libBackgroundGeolocation.a I get the "ENOENT: no such file or directory, scandir '.....ios/include/libBackgroundGeolocation" so I surmise it's at least recognizing that the library is there. </p>
  
  <p>I thought that maybe it was a path problem so I tried setting the library include path explicitly in build.xcconfig using the full path to the platforms/ios directory. </p>
  
  <p>No joy. It still doesn't find the library but if I misspell the name of the directory in the -L in build.xcconfig it flags a directory not found error.</p>
  
  <p>I then thought that maybe it had to do with the targets in the library so I followed the recipe here <a href="https://stackoverflow.com/questions/3520977/build-fat-static-library-device-simulator-using-xcode-and-sdk-4/5721978#5721978">Build fat static library (device + simulator) using Xcode and SDK 4+</a> to include multiple targets.</p>
  
  <p>Still no joy.</p>
  
  <p>I suspect I am missing something fundamental.</p>
  
  <p>What am I doing wrong?</p>
  
  <p>Is there a working recent working sample somewhere of how to wrap a static iOS library as a NativeScript plugin?</p>