user2458408
user2458408

Reputation: 79

how to write a makefile in linux for a c program

i have written a c program for doubly-linked-list in linux. the program is named as program2.c. i have compiled it using "cc program2.c -o out2". it compiled and also executed fine.

even also tried writing a makefile.my makefiel includes

all:doublelinkedlist
doublelinkedlist:program2.c
        gcc -Wall -Werror -O2 -o $@  $<
clean :
        \rm -fr doublelinkedlist 

when i did make it gives me the errors. can any one please help me writing a makefile.

Upvotes: 0

Views: 510

Answers (1)

ugoren
ugoren

Reputation: 16451

When using a makefile, you also started using the -Wall -Werror flags. This is a very good thing. Now the compiler looks for more suspicious things in your program, and refuses to compile if it finds anything. This can be a great help in catching bugs.

However, these warnings mean your program doesn't compile, and you'll need to fix them, by changing the code so that the compiler will be sure all is OK (as far as the compiler can check - of course the code can still contain bugs).

Common issues are mixing different types and not paying attention to the const keyword. But for help with specific warnings, you'll need to show the warnings and the code. Or better - search for each of them in StackOverflow, and I'm sure you'll find good answers.

Upvotes: 1

Related Questions