Ich möchte bauen und verwenden statische Bibliothek (.a) in swift 3. Beispiel: ich baue eine lib halloLib.a, und verwenden Sie es.Wie benutze ich meine statische Bibliothek (.a) in swift 3
hello.c
#include <stdio.h>
#include "hello.h"
int printHello()
{
printf("hello wourl");
return 0;
}
hello.h
#include <stdio.h>
int printHello();
Build: libHello.a und kopieren Sie das Verzeichnis/usr/local/lib
Code swift
Modul .modulmap
module hello [system] {
header "hello.h"
link "libhello"
export *
}
Package.swift
import PackageDescription
let package = Package(
name: "hello",
dependencies: []
)
Verwendung Modul Hallo
main.swift
import hello
printHello()
build mit SWIFT (Befehl): SWIFT build
einen Fehler erhalten:
Compile Swift Module 'usehello' (1 sources)
Linking ./.build/debug/usehello
ld: library not found for -llibhello for architecture x86_64
:0: error: link command failed with exit code 1 (use -v to see invocation)
:0: error: build had 1 command failures
i libhello.a zu libhelloLib.a umbenennen gefunden und ändern "verlinken halloLib ", kompilieren ist ok. Warnung: ld: warning: Objektdatei (/usr/local/lib/libhelloLib.a(hello.o)) wurde für die neuere OSX-Version (10.11) erstellt als verlinkt (10.10) – duck