一直在寻找一个可以编译运行又有脚本语言便利性的语言。
我要的是编译后可以到处运行(相同OS),我非常讨厌,很多语言,还需要在OS 安装一个环境才能运行
如:Java
D语言是由Digital Mars公司开发的编程语言,起因是为了改进C++。它与C二进制兼容(不完全),可编译为本地码,有GC也可手动管理内存,语法上借鉴多种语言,模板则在C++的基础上做了相当大的扩充。D 语言既有 C 语言的强大威力,又有 Python 和 Ruby 的开发效率。它是一种集垃圾回收、手工内存操作、契约式设计、高级模板技术、内嵌汇编、内置单元测试、Mixin 风格多继承、类 Java 包管理机制、内置同步机制、内建基本运行时信息的系统级编程语言。
我做了一下测试,D语言满足我的需求
安装
$ wget http://ftp.digitalmars.com/dmd_2.057-0_amd64.deb $ sudo apt-get install libc6-dev $ sudo dpkg -i dmd_2.057-0_amd64.deb
$ cat hello.d #!/usr/bin/rdmd import std.stdio; void main() { writeln("Hello, world!"); }
$ ./hello.d Hello, world!
编译测试
$ dmd hello.d $ dmd hello.d Hello, world!
将编译后的hello文件复制到其他机器上(注:没有安装dmd环境,一台全新安装CentOS 5.6 的机器)
scp hello [email protected]:/tmp ssh [email protected] cd /tmp ./hello
Hello,world!
在新机器上运行成功,表示D语言使用的是GLibc 库,不依赖dmd环境,也可能是静态编译,将dmd 速要的库编译进了hello文件
$ strace ./hello execve("./hello", ["./hello"], [/* 20 vars */]) = 0 brk(0) = 0x12fc000 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fa6436de000 access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory) open("/etc/ld.so.cache", O_RDONLY) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=33668, ...}) = 0 mmap(NULL, 33668, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fa6436d5000 close(3) = 0 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) open("/lib/libpthread.so.0", O_RDONLY) = 3 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\360Y\0\0\0\0\0\0"..., 832) = 832 fstat(3, {st_mode=S_IFREG|0755, st_size=135745, ...}) = 0 mmap(NULL, 2212736, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fa6432a4000 mprotect(0x7fa6432bc000, 2093056, PROT_NONE) = 0 mmap(0x7fa6434bb000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x17000) = 0x7fa6434bb000 mmap(0x7fa6434bd000, 13184, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fa6434bd000 close(3) = 0 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) open("/lib/libm.so.6", O_RDONLY) = 3 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\360>\0\0\0\0\0\0"..., 832) = 832 fstat(3, {st_mode=S_IFREG|0644, st_size=534832, ...}) = 0 mmap(NULL, 2629864, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fa643021000 mprotect(0x7fa6430a3000, 2093056, PROT_NONE) = 0 mmap(0x7fa6432a2000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x81000) = 0x7fa6432a2000 close(3) = 0 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) open("/lib/librt.so.1", O_RDONLY) = 3 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\220!\0\0\0\0\0\0"..., 832) = 832 fstat(3, {st_mode=S_IFREG|0644, st_size=31744, ...}) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fa6436d4000 mmap(NULL, 2128848, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fa642e19000 mprotect(0x7fa642e20000, 2093056, PROT_NONE) = 0 mmap(0x7fa64301f000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x6000) = 0x7fa64301f000 close(3) = 0 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) open("/lib/libc.so.6", O_RDONLY) = 3 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0`\355\1\0\0\0\0\0"..., 832) = 832 fstat(3, {st_mode=S_IFREG|0755, st_size=1572232, ...}) = 0 mmap(NULL, 3680296, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fa642a96000 mprotect(0x7fa642c10000, 2093056, PROT_NONE) = 0 mmap(0x7fa642e0f000, 20480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x179000) = 0x7fa642e0f000 mmap(0x7fa642e14000, 18472, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fa642e14000 close(3) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fa6436d3000 mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fa6436d1000 arch_prctl(ARCH_SET_FS, 0x7fa6436d19c0) = 0 mprotect(0x7fa642e0f000, 16384, PROT_READ) = 0 mprotect(0x7fa64301f000, 4096, PROT_READ) = 0 mprotect(0x7fa6432a2000, 4096, PROT_READ) = 0 mprotect(0x7fa6434bb000, 4096, PROT_READ) = 0 mprotect(0x686000, 4096, PROT_READ) = 0 mprotect(0x7fa6436e0000, 4096, PROT_READ) = 0 munmap(0x7fa6436d5000, 33668) = 0 set_tid_address(0x7fa6436d1c90) = 31762 set_robust_list(0x7fa6436d1ca0, 0x18) = 0 futex(0x7fffcc6c236c, FUTEX_WAKE_PRIVATE, 1) = 0 futex(0x7fffcc6c236c, FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME, 1, NULL, 7fa6436d19c0) = -1 EAGAIN (Resource temporarily unavailable) rt_sigaction(SIGRTMIN, {0x7fa6432a9870, [], SA_RESTORER|SA_SIGINFO, 0x7fa6432b38f0}, NULL, 8) = 0 rt_sigaction(SIGRT_1, {0x7fa6432a9900, [], SA_RESTORER|SA_RESTART|SA_SIGINFO, 0x7fa6432b38f0}, NULL, 8) = 0 rt_sigprocmask(SIG_UNBLOCK, [RTMIN RT_1], NULL, 8) = 0 getrlimit(RLIMIT_STACK, {rlim_cur=8192*1024, rlim_max=RLIM_INFINITY}) = 0 brk(0) = 0x12fc000 brk(0x131d000) = 0x131d000 rt_sigaction(SIGUSR1, {0x465cac, ~[RTMIN RT_1], SA_RESTORER|SA_RESTART, 0x7fa6432b38f0}, NULL, 8) = 0 rt_sigaction(SIGUSR2, {0x465dcc, ~[RTMIN RT_1], SA_RESTORER, 0x7fa6432b38f0}, NULL, 8) = 0 mmap(NULL, 1048576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fa6435d1000 clock_getres(CLOCK_MONOTONIC, {0, 1}) = 0 sched_getparam(31762, { 0 }) = 0 sched_getscheduler(31762) = 0 (SCHED_OTHER) sched_get_priority_min(SCHED_OTHER) = 0 sched_get_priority_max(SCHED_OTHER) = 0 open("/etc/localtime", O_RDONLY) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=447, ...}) = 0 fstat(3, {st_mode=S_IFREG|0644, st_size=447, ...}) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fa6436dd000 read(3, "TZif2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\5\0\0\0\5\0\0\0\0"..., 4096) = 447 lseek(3, -261, SEEK_CUR) = 186 read(3, "TZif2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\5\0\0\0\5\0\0\0\0"..., 4096) = 261 close(3) = 0 munmap(0x7fa6436dd000, 4096) = 0 rt_sigaction(SIGSEGV, {0x44cb08, ~[RTMIN RT_1], SA_RESTORER|SA_RESETHAND|SA_SIGINFO, 0x7fa6432b38f0}, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGBUS, {0x44cb08, ~[RTMIN RT_1], SA_RESTORER|SA_RESETHAND|SA_SIGINFO, 0x7fa6432b38f0}, {SIG_DFL, [], 0}, 8) = 0 rt_sigaction(SIGSEGV, {SIG_DFL, [], SA_RESTORER, 0x7fa6432b38f0}, NULL, 8) = 0 rt_sigaction(SIGBUS, {SIG_DFL, [], SA_RESTORER, 0x7fa6432b38f0}, NULL, 8) = 0 fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 0), ...}) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fa6436dd000 write(1, "Hello, world!\n", 14Hello, world! ) = 14 munmap(0x7fa6435d1000, 1048576) = 0 exit_group(0) = ?