标签: gnu-make

简单的 gnu make makefile 规则可从多个源文件构建 GCC 可执行文件

我正在尝试制作一个尽可能简单的使用数学库的 make 文件(下面是 fmax,其余的是本次考试的 C cruft):

简单.c:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(int argc, const char *argv[]) {
  double x=atof(argv[1]);
  double y=atof(argv[2]);
  double z=fmax(x,y);
  printf("max(%f,%f)=%f\n",x,y,z);
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

生成文件:

CFLAGS=-g
LDFLAGS=-lm

easy : easy.c
Run Code Online (Sandbox Code Playgroud)

然而,这会产生链接错误(缺少 fmax)。这是因为 make 将 LDFLAGS 首先放置在编译行中:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(int argc, const char *argv[]) {
  double x=atof(argv[1]);
  double y=atof(argv[2]);
  double z=fmax(x,y);
  printf("max(%f,%f)=%f\n",x,y,z);
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

当然,如果我使用显式规则显式地将 LDFLAGS 放在末尾,则它会起作用:

CFLAGS=-g
LDFLAGS=-lm

easy : easy.c
    $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
Run Code Online (Sandbox Code Playgroud)

当然,现在理解 …

c gcc makefile gnu-make

0
推荐指数
1
解决办法
65
查看次数

对于Makefile变量的每个目标

我的makefile看起来如下

apps = app1 app2 app3

all: dir app1 app2 app3 zip cleanup

现在我想在appsvarible 列表上做一些循环,

就像是

`loop on apps

endloop`
Run Code Online (Sandbox Code Playgroud)

是否有可能在makefile上循环,我需要在appsvarible列表上进行循环

更新

可以说,该变量(apps是)生成由我中的程序make文件,它提供了应用程序的每个项目不同势值,有时其apps= app1 app2有时其apps= app1有时可以是20个应用程式或更多apps= app1 app2 appN

我如何迭代apps变量并做一些事情,例如在每次迭代中打印如下:

now im in `app1`
now im in `app2`
etc
Run Code Online (Sandbox Code Playgroud)

尝试以下时

.PHONY: foo
all: foo
APPS = app1 app2 app3 app4
foo : $(APPS)
    for $$f in $(APPS); do echo $$f is here; done …
Run Code Online (Sandbox Code Playgroud)

linux gnu makefile gnu-make

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

makefile if/else 中的 Shell 循环语法

我已经循环了,我需要添加到它的if else语句中,如果值== app1print x else print y

我尝试过以下操作,但是当我添加时else出现语法错误,

我究竟做错了什么?

runners:
    @for a in $(apps) ; do
       if (( a ==  "app1"));then
        echo first: $$v ;
       else
        echo second: $$v ;
        fi
     done
Run Code Online (Sandbox Code Playgroud)

linux shell gnu makefile gnu-make

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

尽管已安装gcc并正常运行,但如何解决make文件中未找到gcc的错误?

我正在尝试使用GCC和GNU Make编译并链接程序集和c程序,但是当我运行“ make”命令时,即使安装并运行正常,它也会引发错误“找不到GCC” ,在修复了make文件后,现在在第14行中抛出了找不到make命令!

我已经尝试在另一台机器上编译它,但是没有用。当然,我已经尝试运行常规的GCC命令,并且运行良好!使用环境变量似乎一切正常。如果我尝试在没有make的情况下运行命令,则会引发linker.ld语法错误,但是我假设它在我身上。

制作文件:

CC=gcc 
TARGET=bookOs
C_FILES=./kernel.c
OBJS=$(C_FILES:.c=.o) 

all compile: $(TARGET) 
all: finale 
.PHONY: all compile clean finale 

%.o: 
    gcc -c $(@:.o=.c) -ffreestanding -fno-exceptions -m32 

$(TARGET): $(OBJS) 
    ?$(shell nasm -f elf start.asm -o start.o)
    ?gcc -m32 -nostdlib -nodefaultlibs -lgcc start.o  $? -T linker.ld -o $(TARGET)

finale: 
    ?$(shell cd ~/Desktop/bookOs/) ?
    $(shell cp $(TARGET) ./iso/boot/$(TARGET))
    $(shell grub2-mkrescue iso --output=$(TARGET).iso) 

clean: 
    ?rm -f *.o $(TARGET) $(TARGET).iso 
    ?find . -name \*.o | xargs --no-run-if-empty rm

Run Code Online (Sandbox Code Playgroud)

汇编文件:


bits 32
global _start 
extern …
Run Code Online (Sandbox Code Playgroud)

c linux assembly gcc gnu-make

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

Gnu-Make无法包含makefile

来自文档:

include指令告诉make暂停读取当前的makefile并在继续之前读取一个或多个其他makefile.该指令是makefile中的一行,如下所示:

 include FILENAMES...
Run Code Online (Sandbox Code Playgroud)

FILENAMES可以包含shell文件名模式.




现在,给出一个Makefile:

# we define 'include' from the command-line.
ifdef include


# We create the included Makefile
$(shell echo 'all : ;' >makefile.include)

# And we include it.
# The docs say: "FILENAMES can contain shell file name patterns."
include *.include


else


endif
Run Code Online (Sandbox Code Playgroud)

跑步,我们得到:

$ rm -rf makefile.include && make include=1
makefile:6: *.include: No such file or directory
Run Code Online (Sandbox Code Playgroud)


那么,这里发生了什么?我们显然有:

c shell makefile gnu-make

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

可以加快MinGW Make而不禁用隐式规则吗?

已知MinGW下的GNU Make在某些情况下会非常慢,因为它执行隐式规则以及Windows如何公开文件信息(每个" MinGW"make"启动非常慢 ").

我在互联网上发现的上一个问题和所有其他资源问题建议通过完全使用-r标志禁用隐式规则来解决问题.但还有另一种方式吗?

我有一个依赖它们的"可移植"Makefile,我想这样做每次启动它都不需要花一分钟时间,而不是让Makefile所有者为我改变它.

mingw makefile gnu-make msys

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

更改了 C 程序中的注释及其导致的分段错误

这是提交之间的区别,只是注释和行间距不同,但旧的提交正常运行,而新的结果导致段错误:

Binary files a/recover/recover and b/recover/recover differ
diff --git a/recover/recover.c b/recover/recover.c
index f0ffdf6..02ab42b 100644
--- a/recover/recover.c
+++ b/recover/recover.c
@@ -1,34 +1,32 @@
-#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdint.h>
 #include <string.h>
 
 typedef enum
 {
-   false,
-   true
-} bool;
+   true,
+   false
 
-typedef uint8_t BYTE;
+} bool;
 
 typedef char *string;
 
+typedef uint8_t BYTE;
 int BLOCK_SIZE = 512;
 
 int main(int argc, char *argv[])
 {
-   // Check if a file name was provided as an argument
-   if …
Run Code Online (Sandbox Code Playgroud)

c gcc clang gnu-make segmentation-fault

-8
推荐指数
1
解决办法
64
查看次数

标签 统计

gnu-make ×7

makefile ×5

c ×4

gcc ×3

linux ×3

gnu ×2

shell ×2

assembly ×1

clang ×1

mingw ×1

msys ×1

segmentation-fault ×1