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
Post a Comment