Skip to content

I'm glad to tell you something about Part 28 #74

@TikaFlow

Description

@TikaFlow

Hi, doctor:

I'm not sure if you're still following this repo, but I sincerely want to give you some response.

in Part-28, you mentioned that:

One annoyance is that I'm still calling the external C compiler cc to do the linking.
...
I assume that it should be possible to do a similar command on current Linux, but so far my Google-fu isn't enough to work this out. If you read this and know the answer, let me know!

Now I know how to link without using gcc:

Assuming we have a obj file named out.o, we can execute the following command to generate an executable file:

$ ld -o out out.o /lib/x86_64-linux-gnu/crt1.o -lc -dynamic-linker /lib64/ld-linux-x86-64.so.2
  • crt1.o is a starter which calls main
  • -lc link libc or other libs if we need
  • ld-linux-x86-64.so.2 helps to load dynamic libs

If ld-linux-x86-64.so.2 or crt1.o is not found, you may find them by locate or any other command.

I don't know if additional parameters will be needed in the future, but they do work for now.


If you see this message, please tell me it works.

Thanks :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions