D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 20587 - _rt_loadLibrary symbol not found
Summary: _rt_loadLibrary symbol not found
Status: RESOLVED DUPLICATE of issue 16391
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Mac OS X
: P1 blocker
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-02-19 19:51 UTC by Jonathan Arnold
Modified: 2020-02-20 20:20 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Jonathan Arnold 2020-02-19 19:51:04 UTC
I'm trying to compile a small test program:

module MacOS.tf;

import std.stdio;
import core.runtime;

void main() {
  void* vhandle = Runtime.loadLibrary("igvideo");
}

on Mac OSX Catalina, and I am getting the following error:

(dmd-2.090.1) dmd tf.d
Undefined symbols for architecture x86_64:
  "_rt_loadLibrary", referenced from:
      __D4core7runtime7Runtime__T11loadLibraryZQoFMxAaZPv in tf.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error: linker exited with status 1

This is similar to bug #19801, but a much simpler case.
Comment 1 Adam D. Ruppe 2020-02-19 19:55:32 UTC
Does it work if you do `dmd -defaultlib=libphobos2.so` ?
Comment 2 Jonathan Arnold 2020-02-19 19:57:15 UTC
Thanks for the comment but no, doesn't help :(
Comment 3 Adam D. Ruppe 2020-02-19 19:58:12 UTC
OK, I know that helps on Linux but not mac I guess :(

will have to wait till someone else gets on.
Comment 4 Mathias LANG 2020-02-20 07:16:52 UTC
Introduced by https://github.com/dlang/druntime/pull/593
The symbol is available on Linux but not OSX.

We can (should) make it available on OSX, because linker errors are not user friendly.
But even if we make it available on OSX, it is not implemented, so you'll have better luck calling `dlopen` / `dlsym` directly.
Comment 5 Jonathan Arnold 2020-02-20 14:31:38 UTC
Actually, it works on Windows as well. And while linker errors are not, as you say, user friendly, even worse, I think, is to add it but not implement it. Is the fact it only works on Windows (and Linux I guess) documented anywhere?
Comment 6 Jonathan Arnold 2020-02-20 14:34:45 UTC
I was having the same error with ldc2 and adding '-link-defaultlib-shared' fixed it:

ldc2 -link-defaultlib-shared tf.d

Is there something similar to that flag for dmd, or is that only for ldc2?

https://github.com/ldc-developers/ldc/issues/3331
Comment 7 kinke 2020-02-20 19:59:54 UTC
This is a duplicate of https://issues.dlang.org/show_bug.cgi?id=16391.

*** This issue has been marked as a duplicate of issue 16391 ***
Comment 8 kinke 2020-02-20 20:20:08 UTC
It works for LDC, with shared druntime only (i.e., not with static druntime), because it has proper shared druntime support on Mac too, unlike DMD. It's using a generalized `rt.sections_elf_shared` in druntime for Mac targets. So https://github.com/dlang/druntime/pull/2322 would fix this, but needs compiler support from DMD.