Jam*_*sev 4 c environment makefile
我在想 ...
当您进行更改为file1.c或file2.c或者file1.h,下面的Makefile只重新编译所需的内容(这是很好)
# Link to executable
result: file1.o file2.o
gcc file1.o file2.o -o result23
# Assemble to .o object files
file1.o: file1.s
gcc -c dist/file1.s
file2.o: file2.s
gcc -c dist/file2.s
# Compile to .s assembly files
file1.s: file1.c
gcc -S file1.c
file2.s: file2.c
gcc -S file2.c
Run Code Online (Sandbox Code Playgroud)
但是,当我将构建的对象移动到另一个目录时,无论是否只更改了1个文件的内容,所有内容都会一直重建.
# Link to executable
result: file1.o file2.o
gcc file1.o file2.o -o result23
# Assemble to .o object files
file1.o: file1.s
gcc -c dist/file1.s
mv file1.o dist
file2.o: file2.s
gcc -c dist/file2.s
mv file2.o dist
# Compile to .s assembly files
file1.s: file1.c
gcc -S file1.c
mv file1.s dist
file2.s: file2.c
gcc -S file2.c
mv file2.s dist
Run Code Online (Sandbox Code Playgroud)
这似乎发生了,因为make不知道.o文件在其环境中的位置.
有了这几个问题:
要修复您的构建,您需要执行以下操作:
# Link to executable
result: dist/file1.o dist/file2.o
gcc dist/file1.o dist/file2.o -o result
# Assemble to .o object files in main directory
dist/file1.o: dist/file1.s
gcc -c dist/file1.s -o dist/file1.o
dist/file2.o: dist/file2.s
gcc -c dist/file2.s -o dist/file2.o
# Compile to .s assembly files
dist/file1.s: file1.c
gcc -S file1.c -o dist/file1.s
dist/file2.s: file2.c
gcc -S file2.c -o dist/file2.s
Run Code Online (Sandbox Code Playgroud)
你当然可以在make中使用环境变量..虽然我不确定这与你的问题的核心有什么关系:只需使用这样的东西,设置BUILDDIR和OBJDIR并有一个像这样的makefile:
$(BUILDDIR)/foo : $(OBJDIR)/bar.o
g++ $(OBJDIR)/bar.o -o $(BUILDDIR)/foo
Run Code Online (Sandbox Code Playgroud)
虽然你可以使用自动变量使这个(以及我的固定makefile)更好:
$(BUILDDIR)/foo : $(OBJDIR)/bar.o
g++ $? -o $@
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5069 次 |
| 最近记录: |