Error when compiling with `--link-libc=no`
Let’s say I have the following C3 program:
import std::io;
fn void main() {
io::printn("hello");
}
If I try to compile with c3c compile main.c3, it works as expected. However, I want to compile a statically-linked executable. But if I try to compile with c3c compile --link-libc=no main.c3, I get the following error:
ld.lld: error: unable to find library -ldl
Failed to create an executable: (null)
I can't reproduce this. What version of C3 are you using? I think it was fixed in 0.6.6.
I realized that the version of C3 I was using was 0.6.5. I updated to the latest commit from the master branch. However, now when I try to compile with --link-libc=no, I get a different error:
ld.lld: error: undefined symbol: __stack_chk_fail
>>> referenced by builtin.c3:0
>>> std.core.builtin.o:(std.core.builtin.panicf)
>>> referenced by formatter_private.c3:0
>>> std.io.o:(std.io.Formatter.floatformat)
>>> referenced by formatter_private.c3:0
>>> std.io.o:(std.io.Formatter.ntoa)
>>> referenced 2 more times
Failed to create an executable: (null)
It's the stack protector added by default. Easiest way to get rid of it is to use -g0
When compiling with --link-libc=no -g0, I get this linker warning:
ld.lld: warning: cannot find entry symbol _start; not setting start address
And then when trying to run the program, I get:
segmentation violation--core dumped
It seems like -g0, when combined with --link-libc=no, causes the entry point to the program to be missing.
Yes, that is completely normal @amarz45
If you do not link libc, then you need to provide all the necessary libraries to link with yourself.
Can this be closed?
I'll close it then.