简体   繁体   English

如何在C中制作一个'makefile'

[英]How to make a 'makefile' in c

I can't understand how I can produce a makefile for C code 我不明白如何为C代码生成Makefile

I have the following .c file which normally I execute in the following manner: 我有以下.c文件,通常按以下方式执行:

gcc server.c -o server.out -lpthread

Once compiled, I run the .out file like this: 编译后,我将运行.out文件,如下所示:

./server.out 4000

EDITED 已编辑

I only need the make files to compile the program rather than running it too.. 我只需要make文件来编译程序,而不是运行它。

To start , you can create a project in eclipse and it would create a makefile for you. 首先,您可以在eclipse中创建一个项目,它将为您创建一个makefile。 And then you can start going into the details about what all is added and this can trim out things you understand are not necessary. 然后,您可以开始查看有关所有添加内容的详细信息,这可以删除您认为不需要的内容。

If naming your executable file server will do for you, then just 如果命名可执行文件server可以帮到您,那么只需

LDLIBS=-lpthread
all: server

in a file called Makefile will do. 在名为Makefile的文件中即可。 The you can just type 您可以输入

make

to build it. 建立它。

Ortherwise your Makefile should contain: 否则,您的Makefile应该包含:

server.out: server.c
        gcc server.c -o server.out -lpthread

Except that it is a tabulation, not spaces before the text “ gcc ”. 除了是制表符之外 ,在文本“ gcc ”之前不能留空格

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

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