Difference between revisions of "D (programming language)"

From ArchWiki
Jump to: navigation, search
m (use Bug template)
 
(9 intermediate revisions by 5 users not shown)
Line 1: Line 1:
[[Category:Programming language]]
+
[[Category:Programming languages]]
 +
[[ja:D]]
 
From [[Wikipedia:D (programming language)]]:
 
From [[Wikipedia:D (programming language)]]:
 
:"The D programming language, also known simply as D, is an object-oriented, imperative, multi-paradigm system programming language by Walter Bright of Digital Mars. It originated as a re-engineering of C++, but even though it is predominantly influenced by that language, it is not a variant of it. D has redesigned some C++ features and has been influenced by concepts used in other programming languages, such as Java, C#, and Eiffel".
 
:"The D programming language, also known simply as D, is an object-oriented, imperative, multi-paradigm system programming language by Walter Bright of Digital Mars. It originated as a re-engineering of C++, but even though it is predominantly influenced by that language, it is not a variant of it. D has redesigned some C++ features and has been influenced by concepts used in other programming languages, such as Java, C#, and Eiffel".
  
 
== Installation ==
 
== Installation ==
To program in D you will need two things - a D compiler and a library. The official compiler is called {{Pkg|dmd}} which is available in [[official repositories]]. It will pull the standard library {{Pkg|libphobos}} in as a dependency.
+
To program in D you will need two things - a D compiler and a library. Easiest way to get started fast is to install {{Grp|dlang-dmd}} package group. It will provide the official compiler ({{Pkg|dmd}}), standard lbrary {{Pkg|libphobos-devel}} and collection of small development tools {{Pkg|dtools}}.
  
 
== Testing the installation ==
 
== Testing the installation ==
Line 31: Line 32:
  
 
== Considerations ==
 
== Considerations ==
There are however possible choices regarding the compiler you choose. The standard is dmd, but GDC (GNU D Compiler) and LDC (LLVM D Compiler) are also popular. There are packages in the AUR for both of these should you find it interesting.
+
There are however possible choices regarding the compiler you choose. The standard (reference one) is dmd, but {{Pkg|gdc}} (GNU D Compiler) and {{Pkg|ldc}} (LLVM D Compiler) are also popular. Those are also in [community].
  
The main difference is that the dmd's back end is not FOSS (licensed from Symantec), while the others compilers are completely FOSS, both back- and front-end.
+
The main difference is that the dmd's back end is not FOSS (licensed from Symantec), while the others compilers are completely FOSS. All 3 compilers share same front-end code and thus have almost identical support for language features (assuming same front-end version).
 +
 
 +
== hardening-wrapper ==
 +
 
 +
In Arch Linux {{Pkg|dmd}} and {{Pkg|libphobos}} packages are built without PIC support.
 +
Using {{Pkg|hardening-wrapper}} forces building executables with PIC support which results in:
 +
 
 +
dmd app.d
 +
/usr/bin/ld: app.o: relocation R_X86_64_32 against  `__dmd_personality_v0' can not be used when making a shared object;  recompile with -fPIC
 +
app.o: error adding symbols: Bad value
 +
collect2: error: ld returned 1 exit status
 +
--- errorlevel 1
 +
 
 +
There are few possible workarounds:
 +
 +
* uninstall {{Pkg|hardening-wrapper}}
 +
* use {{Pkg|gdc}} compiler which is compiled with PIC support
 +
gdc app.d
 +
or for {{Pkg|dub}}
 +
dub --compiler=gdc
 +
* recompile {{Pkg|dmd}} and {{Pkg|libphobos}} with -fPIC flags using [[abs]] or manually
 +
* use clang linker
 +
CC=/usr/bin/clang dmd app.d
 +
if using dub
 +
CC=/usr/bin/clang dub
 +
 
 +
more information
 +
* https://issues.dlang.org/show_bug.cgi?id=15054
 +
* {{Bug|34983}}
 +
* {{Bug|46260}}
 +
* http://wiki.dlang.org/Installing_LDC_on_Gentoo#Hardened_Gentoo
  
 
== Useful libraries and bindings ==
 
== Useful libraries and bindings ==
* [http://code.google.com/a/eclipselabs.org/p/ddt/ DDT] - Eclipse plugin for project and code management in D
+
* [https://code.google.com/p/ddt/ DDT] - Eclipse plugin for project and code management in D
* [http://www.dsource.org/projects/qtd/ QtD] - Qt bindings for D
+
* [http://mono-d.alexanderbothe.com/ Mono-D] - [http://monodevelop.com/ MonoDevelop] addin for programming in D
* [http://www.dsource.org/projects/gtkd GtkD] - An object oriented GTK+ wrapper for D
+
* [https://bitbucket.org/qtd/repo QtD] - Qt bindings for D
* [http://www.dsource.org/projects/derelict Derelict] - Bindings for multimedia libraries, focused toward game development
+
* [http://gtkd.org/ GtkD] - An object oriented GTK+ wrapper for D
* [http://www.dsource.org/projects/bindings Bindings] - A project that houses a lot of bindings to different C libraries
+
* [https://github.com/aldacron/Derelict3 Derelict] - Bindings for multimedia libraries, focused toward game development
* [http://www.dsource.org/projects/descent Descent] - An [[Eclipse]] plugin for programming in D
+
* [https://github.com/D-Programming-Deimos Deimos] - A project that houses a lot of bindings to different C libraries
* [http://www.d-programming-language.org/rdmd.html rdmd] - A utility that allows one to execute D files like shell scripts.
+
* [http://mono-d.alexanderbothe.com/ Mono-D] - An IDE addin for programming in D. (based on [http://monodevelop.com/ MonoDevelop])
+
  
 
== See Also ==
 
== See Also ==
 
* [https://github.com/D-Programming-Language/phobos/ Phobos source on github] - The official Phobos repo
 
* [https://github.com/D-Programming-Language/phobos/ Phobos source on github] - The official Phobos repo
* [http://dlang.org/ Digital Mars] - The official home of D
+
* [http://dlang.org/ The D Programming Language] - The official home of D
* [http://www.dsource.org/ dsource] - An open source D community, hosts several open source projects
+
 
* [http://planet.dsource.org/ Planet D] - A collection of blogs about D
 
* [http://planet.dsource.org/ Planet D] - A collection of blogs about D

Latest revision as of 02:02, 31 January 2016

From Wikipedia:D (programming language):

"The D programming language, also known simply as D, is an object-oriented, imperative, multi-paradigm system programming language by Walter Bright of Digital Mars. It originated as a re-engineering of C++, but even though it is predominantly influenced by that language, it is not a variant of it. D has redesigned some C++ features and has been influenced by concepts used in other programming languages, such as Java, C#, and Eiffel".

Installation

To program in D you will need two things - a D compiler and a library. Easiest way to get started fast is to install dlang-dmd package group. It will provide the official compiler (dmd), standard lbrary libphobos-devel and collection of small development tools dtools.

Testing the installation

To make sure that everything is installed and set up correctly, a simple Hello World program should suffice.

import std.stdio;

void main() {
   string yourName = "archer";
   writefln("Hello %s!", yourName);
}

Paste the code into a file, name it hello.d, and run

$ dmd hello.d

in the same directory as the file. You should then be able to execute the program with:

$ ./hello

You can also execute

$ dmd -run hello.d

which will simply compile and run without leaving any object files in the directory.

Considerations

There are however possible choices regarding the compiler you choose. The standard (reference one) is dmd, but gdc (GNU D Compiler) and ldc (LLVM D Compiler) are also popular. Those are also in [community].

The main difference is that the dmd's back end is not FOSS (licensed from Symantec), while the others compilers are completely FOSS. All 3 compilers share same front-end code and thus have almost identical support for language features (assuming same front-end version).

hardening-wrapper

In Arch Linux dmd and libphobos packages are built without PIC support. Using hardening-wrapper forces building executables with PIC support which results in:

dmd app.d
/usr/bin/ld: app.o: relocation R_X86_64_32 against  `__dmd_personality_v0' can not be used when making a shared object;  recompile with -fPIC
app.o: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
--- errorlevel 1

There are few possible workarounds:

gdc app.d 

or for dub

dub --compiler=gdc
  • recompile dmd and libphobos with -fPIC flags using abs or manually
  • use clang linker
CC=/usr/bin/clang dmd app.d

if using dub

CC=/usr/bin/clang dub

more information

Useful libraries and bindings

  • DDT - Eclipse plugin for project and code management in D
  • Mono-D - MonoDevelop addin for programming in D
  • QtD - Qt bindings for D
  • GtkD - An object oriented GTK+ wrapper for D
  • Derelict - Bindings for multimedia libraries, focused toward game development
  • Deimos - A project that houses a lot of bindings to different C libraries

See Also