How to set `ld` option to prevent to "Segmentation fault (core dumped)" when run program using cpp, gcc, as and ld to build

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi, 
Recently I want to use gcc to learning the compiler. And I know the program `gcc` is a collection of preprocessed, compiler, assembler, linker and other tools. So I try to use `gcc -E`,`gcc -S`,`gcc -c` and `gcc -o` to preprocess, compile, assemble and link  to build a program successfully. 


But when I try to use `cpp`, `cpp -S`, `as` and `ld` to build a program, the output of program is wrong.


The source code of program is "helloword" in C.


The command is:


$ cpp ../main.c -o main.i
$ gcc -S main.i
$ as main.s -o main.o
$ ld main.o -o main -I/lib64/ld-linux-x86-64.so.2 -lc -e main


The output of program is:


$ ./main
Hello World!
Segmentation fault (core dumped)


I think reason is `ld`. Because when I use `gcc -o` replace `as`, the program will work fine. 


So I want to know how to set `ld` option can make it work same as `gcc -o`.


Looking forward to your reply, Thanks.




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux