使文件,这是看看好吗? [英] make file, Is this look ok?

查看:101
本文介绍了使文件,这是看看好吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

all: run

run: test.o list.o matrix.o smatrix.o
    gcc test.o list.o matrix.o smatrix.o -o matrix-mul

list.o: list.c list.h
    gcc -g -c list.c 

matrix.o: matrix.c matrix.h
    gcc -g -std=c99 -c -o matrix.o matrix.c

smatrix.o: smatrix.c smatrix.h
    gcc -g -c -o smatrix.o smatrix.c

test.o: test.c test.h
    gcc -g -c test.c 

我有很多问题,使一个makefile,我终于得到了这个工作。我只是想确保这些都OK了(不只是使程序运行,但一个很好的make文件的期限)

I was having lots of problems to make a makefile and I finally got this working. And I just want to make sure these are ok (not just for making program running but in term of a good make file)

一个问题是,为什么matrix.o和smatrix.o在该行的gcc -g -c .o文件...其中作为list.o和test.o没有该行..

One question is that why do matrix.o and smatrix.o have .o files in the line gcc -g -c ... where as list.o and test.o don't have that line..

我不得不添加-std = C99,因为我得到了一些奇怪的循环错误,但还是不明白为什么我需要在该行把matrix.o ..

I had to add -std=c99 because I was getting some weird for loop error but still don't understand why I need to put matrix.o in the line..

推荐答案

该文件是确定十岁上下。这不是很容易维护。

The file is OK-ish. It is not very easily maintainable.

本网站有关于如何使漂亮的makefile一个很好的教程:
http://mrbook.org/tutorials/make/

This website has a really good tutorial on how to make nice makefiles: http://mrbook.org/tutorials/make/

特别是看看最后一个例子:

Especially look at the last example:

CC=g++
CFLAGS=-c -Wall
LDFLAGS=
SOURCES=main.cpp hello.cpp factorial.cpp
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=hello

all: $(SOURCES) $(EXECUTABLE)

$(EXECUTABLE): $(OBJECTS) 
    $(CC) $(LDFLAGS) $(OBJECTS) -o $@

.cpp.o:
    $(CC) $(CFLAGS) $< -o $@

这应该告诉你如何提高可维护性(额外的文件添加到来源,其余的是自动完成的。

This should show you how to enhance maintainability (add extra files to SOURCES, and the rest is done automatically.

这篇关于使文件,这是看看好吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆