Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Using dlopen / dlsym to call C functions from Swift
import Darwin
let handle = dlopen("/usr/lib/libc.dylib", RTLD_NOW)
let sym = dlsym(handle, "random")
let functionPointer = UnsafeMutablePointer<() -> CLong>(sym)
let result = functionPointer.memory()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment