AnswerBun.com

How to use static library and module map file with Swift?

I’m trying to include a 3rd party static library in my Swift project. I have these two files, among a few others.

GoogleConversionTrackingSDK/ACTReporter.h
GoogleConversionTrackingSDK/libGoogleConversionTracking.a

I added the .a file to the target’s “Linked Frameworks and Library” section. I then created a module.map file in my project, like this:

module GoogleConversionTracking {
    header "../../Libs/GoogleConversionTrackingSDK/ACTReporter.h"    
    export *
}

And in Swift files I can now refer to it:

import GoogleConversionTracking

But I get an error at link time:

ld: library not found for -lGoogleConversionTracking
clang: error: linker command failed with exit code 1 (use -v to see invocation)
note: library not found for -lGoogleConversionTracking

How do you fix this? I would like to not use a bridging header, but instead use these module definition files, if possible.

Stack Overflow Asked by Rob N on January 2, 2021

1 Answers

One Answer

Module map is my synonym for trouble! Bridging headers suck, but they just work in most cases. Anyways, make sure to:

  • Configure SWIFT_INCLUDE_PATHS – a list of paths to be searched by the Swift compiler for additional Swift modules. This tells Xcode where your module maps are.
  • Configure LIBRARY_SEARCH_PATHS – this is a list of paths to folders to be searched by the linker for libraries used by the product. Xcode still needs to know where binaries for your modules are.

Also, you probably want to use the umbrella header, not just header, see documentation. I'd also suggest using modulemap extension, not sure if module.map makes difference, but that's how I remember seeing and using it in most projects.

Omar Abdelhafith has a wicked blog post on this matter and it also helps to see how others do it when dealing with those kind of things.

Answered by Ian Bytchek on January 2, 2021

Add your own answers!

Related Questions

Unable to understand error in D flip flop code

2  Asked on November 29, 2021 by chaitanya_12789

 

Git: Stashed Changes But Still Can’t Pull

1  Asked on November 29, 2021 by crawfordbenjamin

     

elif a==”no”: ^ SyntaxError: invalid syntax

3  Asked on November 29, 2021 by mayar-kurdi

 

ValueError: Unconverted data remains .000

2  Asked on November 29, 2021 by vbdashes

       

How to make an arraylist for the last dice rolls?

3  Asked on November 29, 2021 by acidixs

 

XMLRead all same Notes

2  Asked on November 29, 2021 by ddave

   

Find the most frequent words that appear in the dataset

3  Asked on November 29, 2021 by pythonnew

   

Jenkins auto generates wrong config for composer

1  Asked on November 29, 2021 by tiny-sunlight

   

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved.