我想在swift 3中構建和使用靜態庫(.a)。例如:我構建了一個 lib helloLib.a,並使用它。如何在swift中使用我的靜態庫(.a)3
的hello.c
#include <stdio.h>
#include "hello.h"
int printHello()
{
printf("hello wourl");
return 0;
}
hello.h
#include <stdio.h>
int printHello();
構建到:libHello.a並複製到/ usr/local/lib目錄
代碼迅速
模塊.modulemap
module hello [system] {
header "hello.h"
link "libhello"
export *
}
Package.swift
import PackageDescription
let package = Package(
name: "hello",
dependencies: []
)
使用模塊招呼
main.swift
import hello
printHello()
構建與SWIFT(命令):迅速構建
得到一個錯誤:
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
我重新命名libhello.a到libhelloLib.a和更改鏈接「 helloLib「,編譯它沒關係。但得到警告: ld:警告:目標文件(/usr/local/lib/libhelloLib.a(hello.o))是爲更新的OSX版本(10.11)構建的,而不是鏈接的(10.10) – duck