2012-04-03 28 views
7

连接d程序我有以下简单的程序:未定义的符号“启动”,同时通过LD

import std.stdio; 

int main(string[] argv) { 
    writeln("Hello, world!"); 

    return 0; 
} 

我建立它,如下所示:

DMD -c -m64 -od/proj/out -w -wi -fPIC -debug \ 
    -g -I/proj/hello -unittest /proj/hello.d 

LD -L/usr/share/dmd/lib/ -arch x86_64 -execute -macosx_version_min 10.7 \ 
    -pie -lm -lpthread -lphobos2 -o /proj/out/hello_app /proj/out/hello.o 

编译通过完美,但与链接stucks以下:

Undefined symbols for architecture x86_64: 
    "start", referenced from: 
    -u command line option 
    (maybe you meant: _D3std9algorithm41__T10startsWithVAyaa6_61203d3d2062TAhTAhZ10startsWithFAhAhZb, _D4core6thread6Thread5startMFZv , _D3std9algorithm91__T10startsWithVAyaa11_62203c20612e74696d6554TAS3std8datetime13PosixTimeZone10TransitionTlZ10startsWithFAS3std8datetime13PosixTimeZone10TransitionlZb , _D3std9algorithm43__T10startsWithVAyaa6_61203d3d2062TAyaTAyaZ10startsWithFAyaAyaZb , _D3std9algorithm41__T10startsWithVAyaa6_61203d3d2062TAxaTaZ10startsWithFAxaaZb , _D3std9algorithm92__T10startsWithVAyaa11_62203c20612e74696d6554TAS3std8datetime13PosixTimeZone10LeapSecondTylZ10startsWithFAS3std8datetime13PosixTimeZone10LeapSecondylZb , _D3std9algorithm92__T10startsWithVAyaa11_62203c20612e74696d6554TAS3std8datetime13PosixTimeZone10TransitionTylZ10startsWithFAS3std8datetime13PosixTimeZone10TransitionylZb) 
ld: symbol(s) not found for architecture x86_64 

我想我忘了一些额外的静态库链接,让它设置everythin克,但究竟是什么?

另外我见过有关如何分别编译和链接到dlang站点某处的说明,但无法找到它。

UPD1:当使用gcc -L/usr/share/dmd/lib/ -lphobos2 -lm -lpthread hello.o GCC的帮助链接,它的工作原理,但我需要使用ld

回答

6

链接时添加-lcrt1.o

LD -L/usr/share/dmd/lib/ -arch x86_64 -execute -macosx_version_min 10.7 \ 
    -pie -lm -lpthread -lphobos2 -lcrt1.o -o /proj/out/hello_app /proj/out/hello.o 

[更新] 啊,你说对了:)

1

发现它由于纯粹的运气!

它应该与-lphobos2 -lm -lpthread-lcrt1.o连接 - 然后一切链接和工作正常。