Linking a dynamically linked executable with ld

前端 未结 2 683
时光取名叫无心
时光取名叫无心 2021-01-19 01:11

i\'m trying to create a dynamically linked executable (elf_i386) without gcc. The program is very simple (only a printf)...here the commands:

$ gcc -c simple         


        
相关标签:
2条回答
  • 2021-01-19 01:25

    Lose the --entry main. main isn't your entry point, _start is. Try this:

    $ gcc -c hello.c
    $ ld -o hello -dynamic-linker /lib/ld-linux.so.2 /usr/lib/crt1.o /usr/lib/crti.o hello.o -lc /usr/lib/crtn.o
    $ ./hello
    hello, world
    $ 
    
    0 讨论(0)
  • 2021-01-19 01:35

    It is not necessary to include the C run time environment i guess unless you are using return from your main().

    We can strip the CRT and just link using :

    ld -o hello -lc -dynamic-linker /lib/ld-linux.so.2 hello.o -e main
    

    Will work.

    0 讨论(0)
提交回复
热议问题