简体   繁体   English

Linux Makefile.am错误“未定义引用”

[英]Linux Makefile.am error “undefined reference to”

When I try t compile my program I have this error 当我尝试编译我的程序时,我有这个错误

undefined reference to `printfHello'

I make a simple program, with three files hello.c, hello1.c and hello.h 我创建了一个简单的程序,包含三个文件hello.c,hello1.c和hello.h

hello1.c: hello1.c:

#include <stdint.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h> 
void printfHello() {
    printf("Hello");
}

hello1.h 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;
}

And I have a Makefile.am 我有一个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

If I do ---> cc hello.c -o hello.c hello1.c . 如果我这样做---> cc hello.c -o hello.c hello1.c。 It works fine. 它工作正常。

I need to define something else in the makefile.am file? 我需要在makefile.am文件中定义其他内容吗?

Thanks. 谢谢。

You have not defined the function printfHello() in any of the file. 您尚未在任何文件中定义函数printfHello()。 Please first define that function first like 请先首先定义该功能

void printfHello()
{
 printf("Hello\n");
}

In file hello1.c change the function PrintHola to printHello. 在文件hello1.c中,将PrintHola函数更改为printHello。 The compiler gives errors because it cannot find the body of printHello when it has a prototype. 编译器会产生错误,因为它在有原型时无法找到printHello的主体。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM