hi, I want to manually link an object file using ld.
I'm just compiling with gcc -c test.c and then i do ld test.o, but it gives me an error.
What am I doing wrong?
hi, I want to manually link an object file using ld.
I'm just compiling with gcc -c test.c and then i do ld test.o, but it gives me an error.
What am I doing wrong?
Well you didn't post your error messages for starters.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
That was because I am sure I'm doing it wrong.
Here it is:
ld: warning: cannot find entry symbol _start; defaulting to 00000000080480a0
When I try to execute the executable, i get "Illegal Instruction".
My prog.c has only the stdio.h header.
Well if you type
gcc -v prog.c
You'll see that an awful lot more options get passed to the linker than what you're doing.
If you're just interested in building programs incrementally, then
gcc -c test.c
gcc -o file test.o
works just fine.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
But I want to do it with "ld", not with "gcc -o".
The read the ld man and figure it out.
So study what gcc -v shows you is being passed to ld, then do the same yourself.
Though what that buys you is highly debatable.
Using the linker 'native' means you really ought to know what you're doing.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.