简体   繁体   English

如何在Linux中为AC程序编写Makefile

[英]how to write a makefile in linux for a c program

i have written ac program for doubly-linked-list in linux. 我已经在Linux中为双向链接列表编写了一个ac程序。 the program is named as program2.c. 该程序名为program2.c。 i have compiled it using "cc program2.c -o out2". 我已经使用“ cc program2.c -o out2”对其进行了编译。 it compiled and also executed fine. 它编译并执行得很好。

even also tried writing a makefile.my makefiel includes 甚至还尝试编写一个makefile.my makefiel包括

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. 谁能帮我写一个makefile文件。

When using a makefile, you also started using the -Wall -Werror flags. 使用makefile时,还开始使用-Wall -Werror标志。 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. 常见的问题是混合使用不同的类型,而不注意const关键字。 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. 或者更好-在StackOverflow中搜索它们中的每一个,我相信您会找到不错的答案。

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

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