Thread: link object file with ld

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    17

    link object file with ld

    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?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    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.

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    17
    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.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    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.

  5. #5
    Registered User
    Join Date
    Oct 2006
    Posts
    17
    But I want to do it with "ld", not with "gcc -o".

  6. #6
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    The read the ld man and figure it out.

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  2. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  3. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  4. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM