c3c icon indicating copy to clipboard operation
c3c copied to clipboard

Error when compiling with `--link-libc=no`

Open amarz45 opened this issue 10 months ago • 6 comments

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)

amarz45 avatar Feb 07 '25 17:02 amarz45

I can't reproduce this. What version of C3 are you using? I think it was fixed in 0.6.6.

lerno avatar Feb 08 '25 20:02 lerno

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)

amarz45 avatar Feb 08 '25 22:02 amarz45

It's the stack protector added by default. Easiest way to get rid of it is to use -g0

lerno avatar Feb 09 '25 00:02 lerno

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.

amarz45 avatar Feb 09 '25 01:02 amarz45

Yes, that is completely normal @amarz45

lerno avatar Mar 10 '25 09:03 lerno

If you do not link libc, then you need to provide all the necessary libraries to link with yourself.

lerno avatar Mar 11 '25 08:03 lerno

Can this be closed?

lerno avatar Oct 10 '25 19:10 lerno

I'll close it then.

lerno avatar Oct 29 '25 00:10 lerno