c - Makefile Difficulties -


makefiles confusing me. trying separate off functions separate file, can't compile. missing? thanks!

makefile:

all: clientfunctions client  clientfunctions.o: clientfunctions.c     gcc -c clientfunctions.c -o clientfunctions.o  client.o: client.c clientfunctions.o     gcc -c client.c -o client.o  client: client.o     gcc client.o -o client 

the .c , .h files simple:

clientfunctions.h

#ifndef _clientfunctions_h #define _clientfunctions_h #endif  void printmenu(); 

clientfunctions.c

#include <stdio.h> #include "clientfunctions.h"  void printmenu() {     fprintf(stdout, "please select 1 of following options\n"); } 

client.c

#include "clientfunctions.h"  int main (int argc, char * argv[]) {     printmenu();     return 0; } 

this error getting:

undefined symbols architecture x86_64: "_main", referenced from: implicit entry/start main executable ld: symbol(s) not found architecture x86_64 clang: error: linker command failed exit code 1 (use -v see invocation) make: *** [clientfunctions] error 1

try following.

all: client  clientfunctions.o: clientfunctions.c     gcc -c clientfunctions.c -o clientfunctions.o  client.o: client.c      gcc -c client.c -o client.o  client: client.o clientfunctions.o     gcc client.o clientfunctions.o -o client 

here more idiomatic way write makefile.

all: client  client: client.o clientfunctions.o     $(cc) -o $@ $^ 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -