This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
How to link a "hello.o" object file manually using ld.exe?
- From: "Fei Chen" <chenfei at gmail dot com>
- To: binutils at sourceware dot org
- Date: Thu, 20 Nov 2008 17:00:48 +0800
- Subject: How to link a "hello.o" object file manually using ld.exe?
Hello, dear authors of MinGW,
I just have one question about the linker, ld.exe. I would greatly
appreciate it if you could explain it a bit to me.
The thing is I already have a "hello.o" generated by as.exe, and want
to link this object file manually by using ld.exe instead of gcc.exe.
But I don't know what else .o and .a library files I should link
together with this "hello.o". The source code is extremely simple with
only one printf message.
FYI, below is the output information when I tried to link the "hello.o" alone.
D:\MinGW>ld -o hello hello.o
hello.o:hello.c:(.text+0x21): undefined reference to `_alloca'
hello.o:hello.c:(.text+0x26): undefined reference to `__main'
hello.o:hello.c:(.text+0x32): undefined reference to `printf'
So, what .o and .a files should I link together? BTW, I am using
WindowsXP. Thanks in advance for any help.
Fei
/* Source Code of hello.c */
#include <stdio.h>
int main()
{
printf("Hello, world!\n");
return 0;
}