GNU是否将模糊地编译为.o文件?

发布于 2025-01-22 12:50:46 字数 418 浏览 3 评论 0 原文

菜鸟问题。我想用对象文件 foo.o bar.c 编译到可执行的 bar 。 我在makefile中有这个:

bar: foo.o 
    cc bar.c foo.o -o bar

我运行 $ make -n 并获得:

cc    -c -o foo.o foo.c 
cc bar.c foo.o -o bar

我正在寻找输出的第一行 cc -c -c -o foo.o foo.c 。我没有将明确的规则编译为 foo.c foo.o Make 在看到A .o 目标时隐含地执行此操作?

Noob question. I want to compile bar.c with object file foo.o to an executable bar.
I have this in a Makefile:

bar: foo.o 
    cc bar.c foo.o -o bar

I run $ make -n and get :

cc    -c -o foo.o foo.c 
cc bar.c foo.o -o bar

I'm looking at the first line of output cc -c -o foo.o foo.c. I didn't write an explicit rule compiling foo.c to foo.o. Does make do this implicitly when it sees a .o target?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鹿港小镇 2025-01-29 12:50:46

是的,gnu make具有内置规则:

编译C程序
NO是由NC自动制作的,其中包含'$(cc)$(cppflags)$(cflags)-c'。

的食谱

链接单个对象文件
N是通过通过C编译器运行链接器(通常称为LD)自动制成的。使用的精确食谱是“ $(cc)$(ldflags)no $(loadlibes)$(ldlibs)'。

因此,您可以写信:

bar: bar.o foo.o

Yes, GNU make has a catalog of built-in rules:

Compiling C programs
n.o is made automatically from n.c with a recipe of the form ‘$(CC) $(CPPFLAGS) $(CFLAGS) -c’.

Linking a single object file
n is made automatically from n.o by running the linker (usually called ld) via the C compiler. The precise recipe used is ‘$(CC) $(LDFLAGS) n.o $(LOADLIBES) $(LDLIBS)’.

so you could just write:

bar: bar.o foo.o
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文