Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
makefile在子目录中构建多个可执行文件_Makefile - Fatal编程技术网

makefile在子目录中构建多个可执行文件

makefile在子目录中构建多个可执行文件,makefile,Makefile,我的目录树是: projecto makefile userfolder/ user.c csfolder/ cs.c 只有当.c文件位于同一文件夹中时,我当前的makefile才能工作。 如何编译那些目录中的.c文件 all: user cs user: user.c gcc -o user user.c cs: cs.c gcc -o CS cs.c 这可以做到: all: user cs userfolder/user

我的目录树是:

projecto
   makefile
   userfolder/
       user.c
   csfolder/
       cs.c
只有当.c文件位于同一文件夹中时,我当前的makefile才能工作。 如何编译那些目录中的.c文件

all: user cs

user: user.c
    gcc -o user user.c

cs: cs.c
    gcc -o CS cs.c
这可以做到:

all: user cs

userfolder/user: userfolder/user.c
    gcc -o $@ $<

csfolder/CS: csfolder/cs.c
    gcc -o $@ $<

如果你学习,你可以编写更通用、功能更强大的makefile。

这是一个相当广泛的问题。我建议你读这本书。是的,整个事情;它很长,但真的很好。