Bug 22034 – The phobos2 is not linked by default with -betterc
Status
RESOLVED
Resolution
INVALID
Severity
critical
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
All
Creation time
2021-06-18T07:57:52Z
Last change time
2021-10-21T13:55:29Z
Keywords
betterC, link-failure
Assigned to
No Owner
Creator
Heromyth
Comments
Comment #0 by bitworld — 2021-06-18T07:57:52Z
Here is a simple code for test:
```
import std.ascii : isLower;
extern(C) void main()
{
bool r = isLower('A');
}
```
To run:
```
dmd app.d -betterC
```
The error message:
```
app.o: In function `main':
source/app.d:(.text.main[main]+0xa): undefined reference to `_D3std5ascii7isLowerFNaNbNiNfwZb'
collect2: error: ld returned 1 exit status
Error: linker exited with status 1
```
The compiler is DMD v2.097.0.
Comment #1 by mipri — 2021-06-18T08:31:35Z
same compiler, non-betterC cc:
cc bcascii.o -o /tmp/dmd_run2D9Hdd -m64 -Xlinker --export-dynamic -L/home/mipri/dmd2/linux/bin64/../lib64 -Xlinker -Bstatic -lphobos2 -Xlinker -Bdynamic -lpthread -lm -lrt -ldl
-betterC cc (with same error):
cc bcascii.o -o /tmp/dmd_run3XoXBx -m64 -Xlinker --export-dynamic -L/home/mipri/dmd2/linux/bin64/../lib64 -lpthread -lm -lrt -ldl
-betterC -L-lphobos2 (build successful)
cc bcascii.o -o /tmp/dmd_runbkX3TQ -m64 -Xlinker --export-dynamic -lphobos2 -L/home/mipri/dmd2/linux/bin64/../lib64 -lpthread -lm -lrt -ldl
This behavior's also seen with a freshly built devel dmd.
Comment #2 by bitworld — 2021-06-19T13:45:36Z
In fact, the -betterc does not work properly since DMD 2.096.0.
What happened since then?
Comment #3 by bitworld — 2021-06-19T13:53:21Z
(In reply to mipri from comment #1)
> same compiler, non-betterC cc:
>
> cc bcascii.o -o /tmp/dmd_run2D9Hdd -m64 -Xlinker --export-dynamic
> -L/home/mipri/dmd2/linux/bin64/../lib64 -Xlinker -Bstatic -lphobos2 -Xlinker
> -Bdynamic -lpthread -lm -lrt -ldl
>
> -betterC cc (with same error):
>
> cc bcascii.o -o /tmp/dmd_run3XoXBx -m64 -Xlinker --export-dynamic
> -L/home/mipri/dmd2/linux/bin64/../lib64 -lpthread -lm -lrt -ldl
>
> -betterC -L-lphobos2 (build successful)
>
> cc bcascii.o -o /tmp/dmd_runbkX3TQ -m64 -Xlinker --export-dynamic -lphobos2
> -L/home/mipri/dmd2/linux/bin64/../lib64 -lpthread -lm -lrt -ldl
>
> This behavior's also seen with a freshly built devel dmd.
You are right. The phobos2 is not linked by default for -betterc.
Comment #4 by pro.mathias.lang — 2021-10-21T13:55:29Z
Not linking Phobos is a feature, not a bug. Linking Phobos means linking in the D runtime, as Phobos depends on it. If you want this to work, use standard C function like `islower` (3).