相关疑难解决方法(0)

GNU make:使用生成的头文件生成自动依赖项

所以我遵循了高级自动依赖生成论文 -

Makefile:

SRCS := main.c foo.c

main: main.o foo.o

%.o: %.c
    $(CC) -MMD -MG -MT '$@ $*.d' -c $< -o $@
    cp $*.d $*.tmp
    sed -e 's;#.*;;' -e 's;^[^:]*: *;;' -e 's; *\\$$;;' \
        -e '/^$$/d' -e 's;$$; :;' < $*.tmp >> $*.d
    rm $*.tmp

clean::
    -rm *.o *.d main

-include $(SRCS:.c=.d)
Run Code Online (Sandbox Code Playgroud)

main.c:

#include "foo.h"

int main(int argc, char** argv) {
  foo() ;
  return 0 ;
}
Run Code Online (Sandbox Code Playgroud)

foo.h:

#ifndef __FOO_H__
#define __FOO_H__

void foo() …
Run Code Online (Sandbox Code Playgroud)

makefile gnu-make auto-generate

11
推荐指数
1
解决办法
1万
查看次数

g++ 不产生调试符号

我正在学习Linux,我的第一步是调整我的项目以在Linux上运行。这是简单的 makefile(主要用于教育目的),它生成文件:

#------------------------BUILD VARIABLES-----------------------------
#   Directories, containing headers
INCLUDE_DIR = ../Include/
#   Output directory which will contain output compiled file
OUTPUT_DIR = ../Bin/Debug/

SOURCES = EngineManager.cpp Geometry.cpp Main.cpp Model.cpp \
      Shaders.cpp TGAImage.cpp 

HEADERS = EngineManager.h Geometry.h Line.h Model.h Shaders.h \
      TGAImage.h Triangle.h

#------------------------BUILD_RULES---------------------------------
TinyRenderBuilding : $(addprefix $(INCLUDE_DIR), $(HEADERS)) $(SOURCES)
    mkdir -p  $(OUTPUT_DIR)
    g++ -std=c++14 -o $(OUTPUT_DIR)TinyRender.out -g -I$(INCLUDE_DIR) $(SOURCES)
Run Code Online (Sandbox Code Playgroud)

我不明白,为什么不g++生成调试符号?-g提出了选项

c++ linux makefile gnu-make

4
推荐指数
1
解决办法
1万
查看次数

Makefile 依赖,什么应该是依赖?

我有一个关于 makefile 依赖项的概念性问题,这是因为我在网上看到了关于此的不一致。

假设我有以下文件:

main.cpp         uses->     my_math.cpp and my_strings.cpp
my_math.cpp      uses->     my_math.h
my_strings.cpp   uses->     my_strings.h
Run Code Online (Sandbox Code Playgroud)

如果我有一个 makefile,一般支出为:

program: $(all_objs)
     g++ $(all_objs) -o program
main.o: ...
     .......
my_math.o: ...
     .......
my_strings.o: ...
     .......
Run Code Online (Sandbox Code Playgroud)

我不知道每个依赖项应该包含什么。比如,math.o #includes my_math.h 和 my_strings.h,这是否意味着如果我更改 my_math.h,main.cpp 需要重新编译?但为什么?它像图书馆一样使用它,对吧?它不需要重新编译 main.cpp 或者是吗?

如,main.o 的结果应该是:

1) main.o: main.cpp
         gcc -c main.cpp

2) main.o: main.cpp my_strings.cpp my_strings.h my_math.cpp my_math.h
         gcc -c main.cpp

3) main.o: main.cpp my_strings.cpp my_strings.h my_math.cpp my_math.h
         gcc -c main.cpp my_strings.cpp my_math.cpp
Run Code Online (Sandbox Code Playgroud)

我对依赖项和链接的工作方式有点迷失。

任何帮助,将不胜感激!谢谢!

c c++ makefile

2
推荐指数
1
解决办法
7187
查看次数

在 Makefiles GCC C 程序中,什么是 .d 文件,什么是通配符。?

在 Makefiles GCC C 程序中,什么是 .d 文件,什么是通配符。?

Rgds,

c gcc makefile

-3
推荐指数
1
解决办法
6155
查看次数

标签 统计

makefile ×4

c ×2

c++ ×2

gnu-make ×2

auto-generate ×1

gcc ×1

linux ×1