gpt4 book ai didi

c++ - 如何在不构建对象的情况下使用 g++ -Lhere -Lthere -lfoo 解析 foo 的库路径?

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:00:22 26 4
gpt4 key购买 nike

我想显示将在编译链接阶段使用的库的显式路径。我想这样做,以便我可以将库作为依赖项添加到单独的对象文件中。

换句话说,我经常使用链接:

g++ myFile.cpp -Lsomewhere -Lelse -Lhere -Lthere -lfoo

有没有一种方法可以强制 g++、ld、ldd 或其他东西使用 -L 来解析“-lfoo”而不实际链接任何东西,以便我可以使用显式路径作为依赖项?有关更明确的信息,请参阅 Makefile Updated Library Dependency .

最佳答案

这并不理想,我希望有一个更清晰的答案,但您可以从 gcc 获取默认搜索路径,然后在每个搜索路径中搜索文件。在 GNU make 中:

libnams = foo bar
dirs = somewhere else here there
dirs += $(subst :, ,$(subst =,,$(word 2,$(shell gcc -print-search-dirs | grep libraries))))
exts = a so
paths = $(foreach L, $(libnams), \
$(firstword $(foreach D, $(dirs), \
$(foreach E, $(exts), \
$(wildcard $(D)/lib$(L).$(E))))))

关于c++ - 如何在不构建对象的情况下使用 g++ -Lhere -Lthere -lfoo 解析 foo 的库路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3206157/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com