All use dlopen/dlsym to libqrencode.so (system-wide via gcc role):
- Haskell: System.Posix.DynamicLinker + foreign import ccall "dynamic"
- F#: Mono P/Invoke DllImport("libqrencode.so")
- COBOL: LINKAGE SECTION for proper struct pointer access
- Nim: dynlib module (loadLib/symAddr)
- Fortran: renamed dlclose binding to avoid symbol collision
- D: core.sys.posix.dlfcn (dlopen/dlsym)
- OCaml: Ctypes.foreign via ocamlfind #require
21 lines
687 B
FSharp
21 lines
687 B
FSharp
open System
|
|
open System.Runtime.InteropServices
|
|
|
|
[<DllImport("libqrencode.so", CallingConvention = CallingConvention.Cdecl)>]
|
|
extern nativeint QRcode_encodeString(string text, int version, int level, int hint, int caseSensitive)
|
|
|
|
[<DllImport("libqrencode.so", CallingConvention = CallingConvention.Cdecl)>]
|
|
extern void QRcode_free(nativeint qr)
|
|
|
|
[<Struct; StructLayout(LayoutKind.Sequential)>]
|
|
type QRcode =
|
|
val version: int
|
|
val width: int
|
|
|
|
let qr = QRcode_encodeString("unsandbox-qr-ok", 0, 1, 2, 1)
|
|
if qr <> IntPtr.Zero then
|
|
let s = Marshal.PtrToStructure<QRcode>(qr)
|
|
printfn "QR:unsandbox-qr-ok:ROWS:%d" s.width
|
|
QRcode_free(qr)
|
|
else
|
|
printfn "QR encode failed"
|