makefile작성하다가..

anycastle의 이미지

File: a.c
#include “a.h”
#include “b.h”
File: b.c
#include “b.h”
File: b.h
#include “common.h”

저소스대로 makefile작성좀알려주세요

jj의 이미지

anycastle님, 작성하다 막혔으면, 일단 작성한 코드를 보여주세요. 틀린점을 지적해주실겁니다.

요즘 올라오는 이런 질문들, 아쉽습니다. 지식in의 영향일까요?

--
콘쏠의힘

--
Life is short. damn short...

eminency의 이미지

예의가 부실한 질문이네요

노루가 사냥꾼의 손에서 벗어나는 것 같이, 새가 그물치는 자의 손에서 벗어나는 것 같이 스스로 구원하라 -잠언 6:5

akbar의 이미지

AAAA

ㅡ,.ㅡ;;의 이미지

저정도는 라면 그냥

makefile 만들지말고..

cc a.c

로.ㅎㅎ


----------------------------------------------------------------------------

mrjh76의 이미지

이래저래... 구찮으면...

qmake 를 사용해보세요~~~ (원래 QT를 위한것이나... QT가 링크되서 그렇지 다른데서도 잘 됩니다!)

# qmake -project
# qmake

위와 같이 명령어 두번치면,,, 서브디렉토리까지 검사해서 자동으로 Makefile 만들어 줍니다!

ssehoony의 이미지

아마 소스파일이 헤더파일의 변경이 있을 때도 재 컴파일 하도록하시는게 목적인가요?
그렇다면

a.o : a.h b.h common.h a.c
b.o : b.h common.h b.c

이런식으로 하시면 되는데요.
매번 헤더 include 까지 신경 쓸려면 귀찮습니다.
만약 common.h 가 stdio.h 를 include 했다면요?
근데 알고 보니 stdio.h 는 sys/type.h 와 sys/time.h 를 include 했다면요?
언제 하나씩 다 추적해 볼 수도 없는 노릇이죠.

이런 의존성 문제를 편리하게 해결하기 위해 gcc에는 다음과 같은 옵션이 있습니다.

       -M  Instead of outputting the result of preprocessing, output a rule suitable for make describing the dependencies of the
           main source file.  The preprocessor outputs one make rule containing the object file name for that source file, a
           colon, and the names of all the included files, including those coming from -include or -imacros command line
           options.
 
           Unless specified explicitly (with -MT or -MQ), the object file name consists of the basename of the source file with
           any suffix replaced with object file suffix.  If there are many included files then the rule is split into several
           lines using \-newline.  The rule has no commands.
 
           This option does not suppress the preprocessor's debug output, such as -dM.  To avoid mixing such debug output with
           the dependency rules you should explicitly specify the dependency output file with -MF, or use an environment vari-
           able like DEPENDENCIES_OUTPUT.  Debug output will still be sent to the regular output stream as normal.
 
           Passing -M to the driver implies -E, and suppresses warnings with an implicit -w.

이걸 활용하는 간다한 예제가 gcc문서에서 본적이 있는 듯 합니다.
자세한건 gcc문서를 참고해 보세요.