Open nonocast opened 2 years ago
通过Xcode可以很方便的在swift项目中加入bridge header和c file,通过命令行也可以实现, 下面介绍的方式是我个人尝试,未必是标准答案,辩证理解:
import-obj-header
src/main.swift
import Foundation func main() { let version = RTMP_LibVersion() print(String(format: "0x%08x", version)) hello() } main()
src/bridge.h
#include "librtmp/amf.h" #include "librtmp/log.h" #include "librtmp/rtmp.h" void hello(void);
Makefile
SRC=src BUILD=build TARGET=$(BUILD)/app all: $(BUILD) $(TARGET) $(TARGET): $(SRC)/main.swift $(BUILD)/foo.o swiftc -import-objc-header $(SRC)/bridge.h -Iinclude -lrtmp -Llib -o $@ $^ $(BUILD): @mkdir -p $@ $(BUILD)/foo.o : $(SRC)/foo.c clang -c -o $@ $< run: $(TARGET) @$(TARGET) clean: @rm -rf $(BUILD) .PHONY: clean run all
code: streamr.zip
通过Xcode可以很方便的在swift项目中加入bridge header和c file,通过命令行也可以实现, 下面介绍的方式是我个人尝试,未必是标准答案,辩证理解:
import-obj-header
增加bridge文件src/main.swift
src/bridge.h
Makefile
code: streamr.zip