账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    makefile疑问
    43
    0

    工作需要最近在看make
    在GNU make官方文档上有个例子没太看明白,有懂的朋友希望给与解答;
    如下Makefile:

    objects = main.o kbd.o command.o display.o \
              insert.o search.o files.o utils.o
    
    edit : $(objects)
            cc -o edit $(objects)
    main.o : main.c defs.h
            cc -c main.c
    kbd.o : kbd.c defs.h command.h
            cc -c kbd.c
    command.o : command.c defs.h command.h
            cc -c command.c
    display.o : display.c defs.h buffer.h
            cc -c display.c
    insert.o : insert.c defs.h buffer.h
            cc -c insert.c
    search.o : search.c defs.h buffer.h
            cc -c search.c
    files.o : files.c defs.h buffer.h command.h
            cc -c files.c
    utils.o : utils.c defs.h
            cc -c utils.c
    clean :
            rm edit $(objects)
            

    在下一小节被修改为如下:

    objects = main.o kbd.o command.o display.o \
              insert.o search.o files.o utils.o
    
    edit : $(objects)
            cc -o edit $(objects)
    
    main.o : defs.h
    kbd.o : defs.h command.h
    command.o : defs.h command.h
    display.o : defs.h buffer.h
    insert.o : defs.h buffer.h
    search.o : defs.h buffer.h
    files.o : defs.h buffer.h command.h
    utils.o : defs.h
    
    .PHONY : clean
    clean :
            rm edit $(objects)

    看官方的文档说有隐含规则?excuse me ?
    官方manual如下:

    It is not necessary to spell out the recipes for compiling the individual C source files, because make can figure them out: it has an implicit rule for updating a ‘.o’ file from a correspondingly named ‘.c’ file using a ‘cc -c’ command. For example, it will use the recipe ‘cc -c main.c -o main.o’ to compile main.c into main.o. We can therefore omit the recipes from the rules for the object files. See Using Implicit Rules.When a ‘.c’ file is used automatically in this way, it is also automatically added to the list of prerequisites. We can therefore omit the ‘.c’ files from the prerequisites, provided we omit the recipe.
    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 打闲 普通会员 1楼

      Makefile是一个文本文件,用于配置C、C++、Objective-C、Swift等语言的编译器。它可以帮助开发者创建一个简单的命令行工具链,以便在编译时设置额外的依赖项和链接选项。

      以下是Makefile的一些常见问题和解决方案:

      1. Makefile文件的位置:Makefile文件应该位于你的项目的根目录中,或者指定在其他目录中。如果你在其他目录中使用Makefile,你需要将Makefile文件移动到根目录中。

      2. Makefile文件的语法:Makefile文件的基本语法是:make [options] <target>. 这个语法允许你指定编译器的选项和目标文件的名称。Makefile文件应该用分号(;)结尾。

      3. Makefile文件中的变量:Makefile文件可以使用变量来指定编译器的选项。例如,你可以使用-D选项来指定在目标文件中包含什么。Makefile文件中的变量应该以等号(=)分隔。

      4. Makefile文件中的命令:Makefile文件可以使用命令来指定编译器的选项。例如,你可以使用-f选项来指定编译器的类型(如c++或objc)。Makefile文件中的命令应该以等号(=)分隔。

      5. Makefile文件中的依赖项:Makefile文件可以使用依赖项来指定编译器的选项。例如,你可以使用-I选项来指定在编译器的头文件列表中包含什么。Makefile文件中的依赖项应该以等号(=)分隔。

      6. Makefile文件中的编译选项:Makefile文件可以使用编译选项来指定编译器的选项。例如,你可以使用-o选项来指定目标文件的名称。Makefile文件中的编译选项应该以等号(=)分隔。

      7. Makefile文件中的链接选项:Makefile文件可以使用链接选项来指定链接器的选项。例如,你可以使用-l选项来指定链接器的类型。Makefile文件中的链接选项应该以等号(=)分隔。

      8. Makefile文件中的参数:Makefile文件可以使用参数来指定编译器的选项。例如,你可以使用-v选项来指定输出的信息。Makefile文件中的参数应该以等号(=)分隔。

      9. Makefile文件的文档:Makefile文件应该包含一个文档,以解释Makefile的语法和规则。Makefile文件的文档应该用斜体(**)表示,以突出显示一些重要的信息。

      10. Makefile文件的错误处理:Makefile文件应该包含一个错误处理块,以处理在编译时可能出现的错误。Makefile文件的错误处理块应该用括号([])包围,并使用make help命令来检查错误处理块的语法。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部