On Sat, Mar 11, 2000 at 02:30:19PM +0100, Marco van de Voort wrote:
> P.s. Could you sent me a minimal C program linking to libc, and the
> commandline to compile it with -nostdlib ?
>
> I could throw all these experiences with non standard linking in a
> little tex doc. ( --nostdlib with and without libc, pure assembler
> instead of c (no gcc), some small chapter about syscall conventions
> etc)
Here's what I have for a test program:
-----
#include <stdio.h>
#include <sys/types.h>
#include <pwd.h>
int main () {
struct passwd *password;
while ( (password = getpwent()) != NULL ) {
printf("login: %s\n", password->pw_name);
}
password = getpwnam("root");
printf("root has uid: %d\n", password->pw_uid);
password = getpwuid(0);
printf("uid 0 is %s\n", password->pw_name);
return 0;
}
-----
I copied /usr/src/lib/libc and /usr/src/lib/csu to the parent dir of
this test, and thus my makefile is:
-----
all: get-test
get-test.o: get-test.c
cc -g -Wall -pedantic -ansi -c -I../libc/include get-test.c
get-test: get-test.o
cc -g -nostdlib -static -L../libc -o get-test \
../csu/i386-elf/crt1.o \
../csu/i386-elf/crti.o \
../csu/i386-elf/crtbegin.o \
get-test.o \
../csu/i386-elf/crtend.o \
../csu/i386-elf/crtn.o \
-lc
clean:
rm -f nss-test get-test *.o *.core *.*~
-----
The ordering above was pointed to me by Chuck Robey who got it using
the -v flag to cc (which shows you what the C compiler is doing to get
good links).
I'm not 100% sure that the -lc should be at the end... more likely it
should be right after (before?) my object file (get-test.o), but it
seems to work both ways.
regards,
-oscar
--
pgp public key: finger [EMAIL PROTECTED]
pgp fingerprint: 6D 18 8C 90 4C DF F0 4B DF 35 1F 69 A1 33 C7 BC
To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message