I believe I'm not seeing the forest for the trees and need some help. Can anybody tell me, why my incredibly simple C program fails to link?
Makefile:
Compiling works with
I don't get it. When I run
Code:
#include <stdio.h>
#include <stdlib.h>
int main( int argc, char **argv ) {
printf( "Hello, world!\n" );
exit(0);
}
Makefile:
Code:
DEBUG=-g
.ifdef RELEASE
CCARGS=
.else
CCARGS=$(DEBUG) -c -Wall -pedantic -std=c99
.endif
LDARGS=-dynamic-linker --dy -L /usr/lib -L /lib -lc
CC=clang
LD=ld
all: main
echo Compilation completed.
main.o: main.c
$(CC) $(CCARGS) -o main.o main.c
main: main.o
$(LD) $(LDARGS) -o main main.o
Compiling works with
clang
bug ld
gives me
Code:
ld -dynamic-linker --dy -L /usr/lib -L /lib -lc -o main main.o
ld: error: /lib/libc.so.7: undefined reference to __progname
ld: error: /lib/libc.so.7: undefined reference to environ
*** Error code 1
Stop.
clang -o test main.o
I get an ELF executable that's also only linked to libc. So why the heck is ld
failing?
Code:
% ldd test
test:
libc.so.7 => /lib/libc.so.7 (0x80024c000)