Makefile 将一个文件链接到依赖于另一个文件的文件

发布于 2025-01-18 03:29:54 字数 211 浏览 4 评论 0原文

我有一个依赖test2.c的文件test1.c,这又取决于libcurl(curl.h) 在我的制作中,当我这样做的时候 gcc test1.o test2.o, 在将test1链接到test2时,它给出了错误 - 对test2.c中使用的所有curl方法的未定义引用。

我如何使test1.c继承test2.c的所有依赖关系,而无需明确执行gcc test1.o test2.o -lcurl

I have a file test1.c which depends on test2.c, which in turn depends on libcurl(curl.h)
In my makefile, when I do
gcc test1.o test2.o,
while linking test1 to test2, it gives error - undefined reference to all the curl methods used in test2.c.

How do I make test1.c inherit all the dependencies of test2.c without explicitly having to do gcc test1.o test2.o -lcurl

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

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

发布评论

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

评论(1

寂寞笑我太脆弱 2025-01-25 03:29:54

Makefile 提供了许多小快捷方式,如果您需要的话,可以更轻松地完成工作。

# $* = "test"
# $^ = all dependencies

test: test1.o test2.o
    gcc -o $* $^

test1.o: test1.c
    # GCC command
test2.o: test2.c
    # GCC command

There are many little shortcuts that Makefile provides that make it easier to get the job done if that is what you are asking.

# $* = "test"
# $^ = all dependencies

test: test1.o test2.o
    gcc -o $* $^

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