【问题标题】:makefile (link 2 source files non is main)makefile(链接 2 个非主要源文件)
【发布时间】:2015-05-13 08:51:49
【问题描述】:

我有一个包含 4 个源文件的项目: RTP.c, RTCP.c RTSP.c main.c 和3个头文件: RTP.h RTCP.h RTSP.h 在将头文件包含在源文件中后,我必须将所有头文件包含在 main 中,并将 RTCP.h 包含在 RTP.c 中,然后将它们链接到 make 文件中,请帮助我理解问题。 RTP.c

    #include "RTP.h"
    #include "RTCP.h"

RTCP.c

    #include "RTCP.h"

RTSP.c

    #include "RTSP.h"

main.c

    #include "RTP.h"
    #include "RTSP.h"

制作文件:

    OBJS = main.o RTPfunctions.o RTCPfunctions.o RTSPfunctions.o
    CC = gcc
    CCFLAGS  = -g

   Client : $(OBJS)
         $(CC) $(OBJS) -o -pthread client

   RTCPfunctions.o : RTCPfunctions.c RTCPfunctions.h
         $(CC) -c -g -pthread RTCPfunctions.c

   RTSPfunctions.o : RTSPfunctions.c RTSPfunctions.h
        $(CC) -c -g  -pthread RTSPfunctions.c

   RTPfunctions.o : RTPfunctions.c RTPfunctions.h RTCPfunctions.h
       $(CC) -c -g -o -pthread RTPfunctions.c RTCPfunctions.o

   main.o : main.c RTPfunctions.h RTSPfunctions.h
      $(CC) -c  -g -o -pthread main.c RTPfunctions.o RTSPfunctions.o

   clean:
     \rm *.o *~ client

【问题讨论】:

  • $(CC) $(OBJS) -o client -pthread 怎么样?和所有其他情况类似。
  • 欢迎来到 Stack Overflow!寻求调试帮助的问题(“为什么这段代码不起作用?”)必须包括所需的行为、特定的问题或错误以及在问题本身中重现它所需的最短代码。没有明确问题陈述的问题对其他读者没有用处。请参阅:How to create a Minimal, Complete, and Verifiable example
  • 只需添加@Eregrith 先生所说的内容,请拨打tour 并阅读How to Ask 以了解我们对问题的期望。 :-)

标签: c makefile


【解决方案1】:

您的问题不是很冗长,但是,快速浏览一下您的 makefile,我们可以说,根据online gcc manual

-o file

将输出放在文件file 中。这适用于正在生成的任何类型的输出,无论是可执行文件、目标文件、汇编文件还是预处理的 C 代码。

基本上,这就是说,-o 的直接下一个参数应该是输出文件名。

另外,要跟随order of linkingpthread库应该放在最后,就像

 $(CC) $(OBJS) -o  client -pthread

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-23
    • 2017-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多