Package Manager: Link to a static library.

Hi everyone,

I’m trying to achieve something relatively simple:

I have a C wrapper around C++ code that is built with CMake. So, I have a set of static libraries (.a files) and one header file.

I’m trying to create a Swift Package that contains those files, so I can include them in a project.

I made a module.modulemap:
module FinBar {
    header "fin_bar.h"
    link finbar
    export *
}

swift build fails as it cannot find the library to link it.

Any suggestions?

Thanks,
Evtim

If it is just the library that cannot be found you may try to pass the directory where the library can be found to xcode. E.g.:

swift build -Xlinker "-L/usr/local/lib"
Regards,

···

--
Fred

From: Evtim Papushev via swift-users <swift-users@swift.org>
Reply: Evtim Papushev <e.papushev@me.com>
Date: 11 October 2017 at 12:00:24
To: swift-users@swift.org <swift-users@swift.org>
Subject: [swift-users] Package Manager: Link to a static library.

Hi everyone,

I’m trying to achieve something relatively simple:

I have a C wrapper around C++ code that is built with CMake. So, I have a set of static libraries (.a files) and one header file.

I’m trying to create a Swift Package that contains those files, so I can include them in a project.

I made a module.modulemap:
module FinBar {
header "fin_bar.h"
link finbar
export *
}

swift build fails as it cannot find the library to link it.

Any suggestions?

Thanks,
Evtim
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

Thanks, but that would not work. Those static library files are not in /usr/lib nor /usr/local/lib. They are part of the package I’m trying to link against.

So, swift build checkouts the repo. Then it should link them from it.

Best,
Evtim

···

On Oct 11, 2017, at 13:49, Fred Appelman <fred@appelman.net> wrote:

swift build -Xlinker "-L/usr/local/lib"

The library files have to live somewhere. You need to tell the linker where to look
So,

swift build -Xlinker -L/path/to/the/libraries -L/path/to/more/libraries

should do the trick. It’s no different than C or C++.

···

On Oct 11, 2017, at 7:23 AM, Evtim Papushev via swift-users <swift-users@swift.org> wrote:

Thanks, but that would not work. Those static library files are not in /usr/lib nor /usr/local/lib. They are part of the package I’m trying to link against.

So, swift build checkouts the repo. Then it should link them from it.

Best,
Evtim

On Oct 11, 2017, at 13:49, Fred Appelman <fred@appelman.net <mailto:fred@appelman.net>> wrote:

swift build -Xlinker "-L/usr/local/lib"

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

You don’t need the -Xlinker. -L/path/to/libraries is fine all by itself.

···

On Oct 11, 2017, at 12:11 PM, Jonathan Prescott via swift-users <swift-users@swift.org> wrote:

The library files have to live somewhere. You need to tell the linker where to look
So,

swift build -Xlinker -L/path/to/the/libraries -L/path/to/more/libraries

should do the trick. It’s no different than C or C++.

On Oct 11, 2017, at 7:23 AM, Evtim Papushev via swift-users <swift-users@swift.org <mailto:swift-users@swift.org>> wrote:

Thanks, but that would not work. Those static library files are not in /usr/lib nor /usr/local/lib. They are part of the package I’m trying to link against.

So, swift build checkouts the repo. Then it should link them from it.

Best,
Evtim

On Oct 11, 2017, at 13:49, Fred Appelman <fred@appelman.net <mailto:fred@appelman.net>> wrote:

swift build -Xlinker "-L/usr/local/lib"

_______________________________________________
swift-users mailing list
swift-users@swift.org <mailto:swift-users@swift.org>
https://lists.swift.org/mailman/listinfo/swift-users

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users