linker - 通过LD链接D程序时 undefined symbol "start"

标签 linker ld d

我有以下简单的程序:

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

编译完美通过,但链接卡住了,如下所示:

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

我想我忘记了一些额外的静态库来链接以让它设置一切,但到底是什么?

此外,我在 dlang 网站上的某个地方看到了有关如何进行单独编译和链接的说明,但找不到它。

UPD1:当使用gcc -L/usr/share/dmd/lib/-lphobos2 -lm -lpthread hello.o在GCC的帮助下进行链接时,它可以工作,但我需要使用ld

最佳答案

链接时添加-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

[更新] 啊,你明白了:)

关于linker - 通过LD链接D程序时 undefined symbol "start",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9996468/

相关文章:

c++ - 链表输出不正确(c++)

c++ - GCC 报告对现有符号的 undefined reference

sockets - D语言Socket.receive()

arrays - D 中不可变长度的可变数组

c++ - 尝试在C++中使用curl时出现未解析的符号

c++ - 调用以对象 vector 作为参数的函数时出现链接错误

c++ - g++/clang++ 中带有 makefile 的参数顺序

gcc - 使用 GCC ARM 工具链链接任意数据

memory-leaks - 如何修复 D "memory leaks"

c++ - 在 g++ 中包含额外的链接器标志有什么坏处吗?