c library in swift project

I have a c library such as libClib.a that i want to use in a mac os swift project in Xcode 8.3.2. i have tried to use a module to do this following these steps:


1. Import Clib in the appropriate source code

2. create module map file, Clib.modulemap

module Clib [system] {

header "_path_to/libClib.h"

link libClib.a

export *

}

3. in Build Settings, I add Import Path "_path_to_Clib.modulemap"

4 in Build Settings, I add Module File "_path_to_Clib.modulemap/Clib.modulemap"

5 in Build Settings, I add to extern libraries "_path_to_libclib.a/libclib.a"

where "_path_to_..." are replaced by the actual hard paths to the respective files


What am I missing?

Replies

I don’t think you need to go down the module map path here (moreover, it’s probably a mis-step because you’re dealing with a static library rather than a framework). Rather:

  1. Add a bridging header to your project

  2. Include the library’s headers in that bridging header

  3. Add the

    .a
    file to your project

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"