dl

package module
v0.0.0-...-00e9c7b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 12, 2016 License: MIT Imports: 8 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

go-dl Build Status Coverage Status

go-dl is a package exposing dynamic library loading features to the Go language.

Dynamically Loading C Libraries

The go-dl package exposes the Open function that taking a library name or path and some options will load the code in memory and return an object allowing interaction with the library.

Here's an example:

package main

import (
    "fmt"
    "unsafe"

    "github.com/achille-roussel/go-dl"
)

func main() {
    var lib dl.Library
    var err error
    var sym unsafe.Pointer

    // Dynamically loads libc on a linux platform.
    // Note that the library names or paths are usually system-dependant.
    if lib, err = dl.Open("libc.so.6", dl.Lazy|dl.Local); err != nil {
        fmt.Println(err)
        return
    }

    defer lib.Close()

    // Get the address of the `puts` symbol, this can be used to call the
    // function using a ffi package.
    if sym, err = lib.Symbol("puts"); err != nil {
        fmt.Println(err)
        return
    }

    // ...
}

Finding C Libraries

go-dl also comes with a function that attempts to emulate the platform's logic for dynamic library discovery in a portable way, here's an example:

package main

import (
    "fmt"

    "github.com/achille-roussel/go-dl"
)

func main() {
    var path string
    var err error

    if path, err = dl.Find("libc"); err != nil {
        fmt.Println(err)
        return
    }

    // Now `path` holds the full path to where the standard C library was found
    // on the system.
    fmt.Println(path)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Find

func Find(name string) (path string, err error)

Types

type Error

type Error struct {
	Message string
}

func (*Error) Error

func (err *Error) Error() string

type Library

type Library interface {
	Close() error

	Symbol(name string) (uintptr, error)
}

func Open

func Open(path string, mode Mode) (Library, error)

type Mode

type Mode int
const (
	Lazy   Mode = 1 << 0
	Now    Mode = 1 << 1
	Global Mode = 1 << 2
	Local  Mode = 1 << 3
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL