undefined reference to `printf'

test.c et noyau.asm sont dans le dossier src, Makefile est dans le dossier Debug, juste comme ça:

src
    test.c
    kernel.asm
Debug
    Makefile

Tous ces fichiers sont très simples codes. Mais si je lance make dans le dossier Debug,j'obtiens l'erreur suivante:

ld -Ttext 0x30400 -o test ../Debug/kernel.o ../Debug/test.o
../Debug/test.o: In function `Print_String':
test.c:(.text+0xf): undefined reference to `printf'

Quelqu'un peut me dire pourquoi? Les contenus sont comme suit:

test.c

#include <stdio.h>

int m = 1;
void Print_String()
{
    printf("TEST");
}

noyau.asm

extern m
extern Print_String

[section .text]
global _start
_start:
    mov eax, m
    call Print_String

Makefile

# This Program
TARGET  = test

# All Phony Targets
.PHONY : everything clean all

DIR     = ..

OBJ     = $(DIR)/Debug/kernel.o $(DIR)/Debug/test.o
C_FILE  = $(DIR)/src/test.c
K_ASM   = $(DIR)/src/kernel.asm

ASM     = nasm
LD      = ld
CC      = gcc

CC_FLAG  = -c -g
ASM_FLAG = -f elf
LD_FLAG  = -Ttext 0x30400

# Default starting position
everything : $(TARGET)

clean :
    rm -f $(TARGET)

all : clean everything

kernel.o : $(K_ASM)
    $(ASM) $(ASM_FLAG) -o $@ $<

test     : $(OBJ)
    $(LD) $(LD_FLAG) -o $@ $(OBJ)

test.o   : $(C_FILE)
    $(CC) $(CC_FLAG) -o $@ $<
l'ajout de -lc à ld ligne de commande peut aider.
Sauf si vous avez votre propre version de printf quelque part, vous aurez un lien avec la bibliothèque d'exécution C (-lc).
Vous mai besoin d'un autre ld drapeau d'ailleurs "-lc", "-I/lib/ld-linux..2". ld, par défaut, cherche "...donc.1" qui donnent une confusion "fichier non trouvé" erreur!

OriginalL'auteur Searene | 2013-02-12