GithubHelp home page GithubHelp logo

d_static_binding's Introduction

Static binding in D

Static binding_ of a C static library in D language

From Static vs. Dynamic Bindings

By static, I mean a binding that allows linking with C libraries or object files directly at compile time. By dynamic, I mean a binding that does not allow linking at compile time, but instead loads a shared library (DLL/so/dylib/framework) at runtime ... So with a static binding in D, a program can be linked at compile time with the static library libBar.a (Posix) for static linkage, or the libBar.so for dynamic linkage. A dynamic binding can not be linked to anything at compile time. No static libraries, no import libraries, no shared objects.

For more information see:

Build clib

The file must be compiled into object file for linking with the D programs:

$ cd ./c
$ make
$ ls -1
clib.c
clib.o
libclib.a
makefile

Build D example

We have two ways:

  1. include clib into exacutable
  2. pass the necessary information to the linker

these two ways are defined in dub as configuration mode1 and mode2:

name "staticbind"
description "Stating binding example"
authors "Orfeo Da Vià"
targetType "executable"

configuration "mode1" {
  targetName "mode1"
  sourceFiles "c/libclib.a"
}

configuration "mode2" {
   targetName "mode2"
   lflags "-L./c" "-lclib"
}

Mode 1

In order to build

dub build -c=mode1

Mode 2

dub build -c=mode2

Linker flags:

   lflags "-L./c" "-lclib"

means:

  • -L/path/to/libraries: the linker searches a standard list of directories for the library. The directories searched include several standard system directories plus any that you specify with `-L``.
  • -lfoo Search the library named foo (or libfoo.a) when linking.

d_static_binding's People

Contributors

o3o avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.