Makefile 在数组中查找

发布于 2024-12-03 01:18:33 字数 387 浏览 0 评论 0原文

如果我有这样的内容:

PROJECTS += path/to/first
PROJECTS += path/to/second
PROJECTS += path/to/third

以及

LIBS += lib_output/first.lib
LIBS += lib_output/second.lib
LIBS += lib_output/third.lib

如何将 PROJECTS += path/to/first 中的项目与 LIBS += lib_output/first.lib 关联起来? makefile 中是否有类似哈希映射的内容?或者可以在数组中搜索?

If I have something like this:

PROJECTS += path/to/first
PROJECTS += path/to/second
PROJECTS += path/to/third

and

LIBS += lib_output/first.lib
LIBS += lib_output/second.lib
LIBS += lib_output/third.lib

How could I associate the project from PROJECTS += path/to/first with LIBS += lib_output/first.lib? Is there something like a hashmap available in a makefile? Or possibility to search in an array?

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

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

发布评论

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

评论(2

独守阴晴ぅ圆缺 2024-12-10 01:18:33

您可以使用计算变量名称来模拟查找表以及创建变量名称的事实可以包含一些特殊字符,例如点和正斜杠:

PROJECTS += path/to/first
PROJECTS += path/to/second
PROJECTS += path/to/third

LIBS += lib_output/first.lib
LIBS += lib_output/second.lib
LIBS += lib_output/third.lib

lookup.path/to/first  := lib_output/first.lib
lookup.path/to/second := lib_output/second.lib
lookup.path/to/third  := lib_output/third.lib

path := path/to/first
$(info ${path} -> ${lookup.${path}})
path := path/to/second
$(info ${path} -> ${lookup.${path}})
path := path/to/third
$(info ${path} -> ${lookup.${path}})

输出:

$ make
path/to/first -> lib_output/first.lib
path/to/second -> lib_output/second.lib
path/to/third -> lib_output/third.lib

You can simulate lookup tables using computed variable names and the fact that make variable names can include some special characters like dot and forward slash:

PROJECTS += path/to/first
PROJECTS += path/to/second
PROJECTS += path/to/third

LIBS += lib_output/first.lib
LIBS += lib_output/second.lib
LIBS += lib_output/third.lib

lookup.path/to/first  := lib_output/first.lib
lookup.path/to/second := lib_output/second.lib
lookup.path/to/third  := lib_output/third.lib

path := path/to/first
$(info ${path} -> ${lookup.${path}})
path := path/to/second
$(info ${path} -> ${lookup.${path}})
path := path/to/third
$(info ${path} -> ${lookup.${path}})

Outputs:

$ make
path/to/first -> lib_output/first.lib
path/to/second -> lib_output/second.lib
path/to/third -> lib_output/third.lib
破晓 2024-12-10 01:18:33

我不确定我是否完全理解你的问题,但我认为 word 函数可能正是你所需要的(它可能是 GNU make 扩展):

$(word 2, $( PROJECTS)) 返回路径/到/第二个
$(word 2, $(LIBS)) 返回 lib_output/second.lib

I'm not sure if I completely understand your question, but I think the word function might be what you need (it may be a GNU make extension):

$(word 2, $(PROJECTS)) returns path/to/second,
$(word 2, $(LIBS)) returns lib_output/second.lib.

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