Compile Swift script using new LAPACK headers

I have a Swift script that imports Accelerate to perform some calculations. When I compile the script on macOS using swiftc main.swift, I get the following warning:

main.swift:11:5: warning: 'slarnv_' was deprecated in macOS 13.3:
The CLAPACK interface is deprecated.
Please compile with -DACCELERATE_NEW_LAPACK to access the new lapack headers.
    slarnv_(&idist, &iseed, &num, &vec)

I tried to compile with swiftc -DACCELERATE_NEW_LAPACK main.swift but I still get the same warning. How am I supposed to compile this script using the new LAPACK headers?

Can you try -Xcc -DACCELERATE_NEW_LAPACK? Flags affecting C headers need to be passed to the underlying ClangImporter instance.

1 Like

What Tony said. You might also want to define ACCELERATE_LAPACK_ILP64, which makes interoperating with swift quite a bit neater in some cases because it replaces all the Int32 params with Int--adopting this would require changes to your Swift code as well, however, so if it's code that you aren't doing further development on, it's probably not worth it.

For anyone who stumbles across this who is using SPM, you'll want to add the following to your Swift target that uses Accelerate:

      cSettings: [
        .define("ACCELERATE_LAPACK_ILP64") // optional
1 Like

Woo hoo! It works. Thanks for the help.

swiftc -Xcc -DACCELERATE_NEW_LAPACK main.swift

I've been using this for my package and it seems to be working fine:

// swift-tools-version: 5.10

import PackageDescription

let package = Package(
    // ...
    targets: [
            cxxSettings: [.define("ACCELERATE_NEW_LAPACK", to: "1")],
            linkerSettings: [.linkedFramework("Accelerate")]
        // ...

Should I use cSettings instead of cxxSettings and linkerSettings?

What you have should work fine, too.