3

我正在尝试在 Mac 上使用带有 D 的 libcurl 来加快速度。

我正在使用最新的 dmd2 编译器(DMD64 D Compiler v2.062)。

以下示例在 Windows 上编译并正常工作:

导入 std.net.curl、std.conv、std.stdio;

void main() {
     string content = to!string(get("dlang.org"));
     writeln(content);
}

在 Mac 上编译时,我得到以下输出:

~/src $ dmd dcurl.d
Undefined symbols for architecture x86_64:
  "_curl_easy_cleanup", referenced from:
      _D3std3net4curl4Curl8shutdownMFZv in libphobos2.a(curl_1522_37c.o)
  "_curl_easy_duphandle", referenced from:
      _D3std3net4curl4Curl3dupMFZS3std3net4curl4Curl in libphobos2.a(curl_151e_149.o)
  "_curl_easy_init", referenced from:
      _D3std3net4curl4Curl10initializeMFZv in libphobos2.a(curl_151d_432.o)
  "_curl_easy_perform", referenced from:
      _D3std3net4curl4Curl7performMFbZi in libphobos2.a(curl_1528_2fb.o)
  "_curl_easy_setopt", referenced from:
      _D3std3net4curl4Curl3setMFE3etc1c4curl10CurlOptionlZv in libphobos2.a(curl_1525_14c.o)
      _D3std3net4curl4Curl3setMFE3etc1c4curl10CurlOptionAxaZv in libphobos2.a(curl_1524_14c.o)
      _D3std3net4curl4Curl3setMFE3etc1c4curl10CurlOptionPvZv in libphobos2.a(curl_1526_14c.o)
      _D3std3net4curl4Curl5clearMFE3etc1c4curl10CurlOptionZv in libphobos2.a(curl_1527_207.o)
  "_curl_easy_strerror", referenced from:
      _D3std3net4curl4Curl11errorStringMFiZAya in libphobos2.a(curl_1520_4a1.o)
  "_curl_global_cleanup", referenced from:
      _D3std3net4curl4Curl19_sharedStaticDtor29FZv in libphobos2.a(curl.o)
  "_curl_global_init", referenced from:
      _D3std3net4curl4Curl19_sharedStaticCtor28FZv in libphobos2.a(curl.o)
  "_curl_slist_append", referenced from:
      _D3std3net4curl3FTP3dupMFZS3std3net4curl3FTP in libphobos2.a(curl_1518_ea.o)
      _D3std3net4curl3FTP10addCommandMFAxaZv in libphobos2.a(curl_1518_ea.o)
      _D3std3net4curl4HTTP3dupMFZS3std3net4curl4HTTP in libphobos2.a(curl_1517_140.o)
      _D3std3net4curl4HTTP16addRequestHeaderMFAxaAxaZv in libphobos2.a(curl_1517_140.o)
  "_curl_slist_free_all", referenced from:
      _D3std3net4curl3FTP4Impl6__dtorMFZv in libphobos2.a(curl_1518_ea.o)
      _D3std3net4curl3FTP13clearCommandsMFZv in libphobos2.a(curl_1518_ea.o)
      _D3std3net4curl4HTTP4Impl6__dtorMFZv in libphobos2.a(curl_1517_140.o)
      _D3std3net4curl4HTTP19clearRequestHeadersMFZv in libphobos2.a(curl_1517_140.o)
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
--- errorlevel 1

这似乎暗示了一个链接问题。

我有 libcurl:/usr/lib/libcurl.3.dylib /usr/lib/libcurl.4.dylib /usr/lib/libcurl.dylib

但我什至不确定 dmd 是否正在尝试使用它们。

我以前用 C/C++ 做过这个(在同一台机器上使用这些库),所以我认为这一定是版本控制问题,否则我需要将一些标志传递给编译器。

非常感激任何的帮助。

4

1 回答 1

5

您需要链接到 libcurl。默认情况下它不链接。所以,而不是

dmd dcurl.d

你需要做

dmd -L-lcurl dcurl.d
于 2013-06-02T01:01:32.497 回答