-
-
Save dedeexe/562e0c5fffe5f33019fd8366645a0d5f to your computer and use it in GitHub Desktop.
Using dlopen / dlsym to call C functions from Swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
println(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment