如何最好地检查 C 库依赖性?

发布于 2024-09-30 12:55:11 字数 601 浏览 0 评论 0原文

我正在构建一些安装高级堆栈的东西,为此,我需要安装较低级别的东西。

查找是否安装了 Java(例如 Java)的最简单方法是在 shell 脚本中取出 which java 并检查是否可以找到它。现在,我需要创建一些没有明显二进制文件的库,例如,基本上是 C.libxml 中的 include 内容。

总的来说,我对 C 还很陌生,所以这对我来说有点棘手。 :) 理想情况下,我可以编写一个 shell 脚本来调用一个小的 C 应用程序,该应用程序调用 #include,其中 xxxx 是我正在检查的库的存在.如果找不到它,就会出错。当然,不幸的是,所有这些都发生在编译之前,因此它并不像我希望的那样动态。

我正在一个可能没有安装任何东西的系统上执行此操作(无论是高级语言还是包管理器还是其他什么),因此我正在寻找更多的基本 shell 脚本方式来执行操作(或者可能是一些聪明的 C 或命令行 gcc 选项)。或者也许只是手动搜索 gcc 无论如何都会查找的包含路径 /usr/local/include/usr/include 等)。有什么想法吗?

I'm building something that installs a high-level stack, and to do that, I need to install the lower-level stuff.

The simplest way to look for whether, say, Java is installed, is to just shell out a which java in a shell script and check if it can find it. I'm now to the point where I need to do some libraries without an obvious binary- basically stuff that is an include from within C. libxml, for example.

I'm woefully green to C in general, so this makes things a little tricky for me. :) Ideally I could just make a shell script that calls a little C applicaiton that calls #include <xxxx>, where xxxx is the library that I'm checking the existence of. If it can't find it, it errors out. Unfortunately, of course, all that happens prior to compilation, so it's not as dynamic as I'd like.

I'm doing this on a system that probably doesn't have anything installed on it (be it high-level language or package managers or what have you), so I'm looking more for a basic shell script way of doing things (or maybe some clever C or command-line gcc options). Or maybe just manually search the include paths that gcc would look for anyway /usr/local/include, /usr/include, etc.). Any thoughts?

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

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

发布评论

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

评论(2

梦中的蝴蝶 2024-10-07 12:55:11

Autotools 确实是您所需要的。它是一个巨大的(而且奇怪的)框架来处理这个问题:
http://www.gnu.org/software/autoconf/

您还可以使用pkg-config,它将与利用该机制的较新软件一起使用:
http://pkg-config.freedesktop.org/wiki/

Autotools is really what you need. Its a huge (and bizarre) framework for dealing with this very problem:
http://www.gnu.org/software/autoconf/

You can also use pkg-config, which will work with newer software making use of that mechanism:
http://pkg-config.freedesktop.org/wiki/

七秒鱼° 2024-10-07 12:55:11

这就是configure的目的(automake和autoconf的一部分)

this is the purpose of configure (part of automake and autoconf)

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