Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux Makefile.am error "undefined reference to"

Tags:

c

linux

makefile

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

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;
}

And I have a 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 . It works fine.

I need to define something else in the makefile.am file?

Thanks.

like image 508
Silvia Gonzalez Avatar asked May 15 '26 19:05

Silvia Gonzalez


1 Answers

You have not defined the function printfHello() in any of the file. Please first define that function first like

void printfHello()
{
 printf("Hello\n");
}
like image 194
Yasir Majeed Avatar answered May 17 '26 09:05

Yasir Majeed



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!