Linux Makefile.am错误 "undefined reference to"

3
当我尝试编译我的程序时,出现了这个错误。
undefined reference to `printfHello'

我编写了一个简单的程序,包含三个文件 hello.c、hello1.c 和 hello.h。
hello1.c:
#include <stdint.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h> 
void printfHello() {
    printf("Hello");
}

hello1.h

void printfHello();

hello.c

#include <stdint.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>   
#include "hello1.h"   

int main() {
    int errn=0;
    printfHello();
    return errn;
}

我有一个Makefile.am。
bin_PROGRAMS = client_ev

AM_CPPFLAGS = \
    -I$(top_srcdir)/include \
    -I$(top_builddir)/include
#   $(some_CFLAGS)

EXTRA_DIST = \
    autogen.sh

MAINTAINERCLEANFILES = \
    configure \
    aclocal.m4 \
    Makefile.in

client_ev_SOURCES = hello.c hello1.c

如果我执行 ---> cc hello.c -o hello.c hello1.c 。它可以正常工作。
我需要在makefile.am文件中定义其他内容吗?
谢谢。
2个回答

1
您还没有在任何文件中定义printfHello()函数。请先像这样定义该函数:
void printfHello()
{
 printf("Hello\n");
}

否则我认为你在hello1.c文件中输入了错误的函数名。 - Yasir Majeed
我把名字打错了,我改正了它,但它仍然不起作用。 - Silvia Gonzalez
为什么下面的Makefile.am中没有将hello.c和hello1.c添加到client_ev_SOURCES行中? client_ev_SOURCES = client_ev.c hola.c hello.c hello1.c - Yasir Majeed

0
在文件 hello1.c 中,将函数 PrintHola 改为 printHello。编译器会报错,因为它找不到具有原型的 printHello 的主体。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接