简体   繁体   English

如何要求一个自动工具项目/获取一个自动工具包的标志?

[英]How to Require an autotools project / get the cflags for an autotools package?

I want to require ac library which was build by with the autotools. 我想要一个使用自动工具构建的交流库。 To be honest I have little to no idea how they work :/ (The library which I want to require is " https://github.com/p4lang/PI ") 老实说,我几乎不知道它们是如何工作的:/(我想要的库是“ https://github.com/p4lang/PI ”)

I have executed the ./configure etc. scripts and successfully installed it. 我已经执行了./configure等脚本并成功安装了它。

When I search my usr I find the library under /usr/local/lib/libpi.a and analogously the header files under /usr/local/include/PI. 当我搜索usr时,我在/usr/local/lib/libpi.a下找到该库,并在/ usr / local / include / PI下找到头文件。

I build my project with cmake and would like to have a cross platform solution with it. 我使用cmake构建我的项目,并希望有一个跨平台的解决方案。 However I would be satisfied to use the pkg-config command. 但是我很满意使用pkg-config命令。

Does anybody know what is the "correct" / "recommended" way to get cflags, or at least a variant in which I do not have to hard code the paths? 有谁知道获取cflag的“正确” /“推荐”方式是什么,或者至少我不需要对路径进行硬编码的变体?

The involvement of the Autotools ends at the point where the built artifacts are installed on the system. Autotools的参与将在系统上安装了构建工件的时候结束。 Using those does not go through the Autotools. 使用这些不会通过自动工具。 * This applies just as much when the installed artifacts are libraries and headers as when they are executables. *当安装的工件是库和标头时,这与可执行文件一样适用。 There's nothing special or different about using Autotools-built programs or libraries. 使用Autotools构建的程序或库没有什么特殊或不同之处。

I build my project with cmake and would like to have a cross platform solution with it. 我使用cmake构建我的项目,并希望有一个跨平台的解决方案。 However I would be satisfied to use the pkg-config command. 但是我很满意使用pkg-config命令。

Just like projects served by any other build system, Autotools projects can build and install pkg-config configuration files, or CMake macros, or whatever other bits and pieces they might think appropriate to assist users, but this is project-specific. 就像任何其他构建系统服务的项目一样,Autotools项目可以构建并安装pkg-config配置文件或CMake宏,或者他们认为合适的任何其他零散片段来帮助用户,但这是特定于项目的。 The Autotools do not create such additional pieces of their own accord, but some Autotools-based projects do add them. Autotools不会自行创建此类额外的片段,但是某些基于Autotools的项目会添加它们。 And some don't, just like some CMake projects don't, and some projects with hand-rolled build systems don't, etc.. 还有一些则没有,就像某些CMake项目没有,有些带有手动构建系统的项目则没有,等等。

Does anybody know what is the "correct" / "recommended" way to get cflags, or at least a variant in which I do not have to hard code the paths? 有谁知道获取cflag的“正确” /“推荐”方式是什么,或者至少我不需要对路径进行硬编码的变体?

Note that typically, for a library whose name you know, the only flags you might need are those specifying the location of the library headers and / or one specifying the location of the libraries themselves. 注意,通常,对于您知道名称的库,您可能需要的唯一标志是那些指定库头的位置和/或一个指定库本身的位置的标志。 Even these are unnecessary if the relevant pieces are installed in places that the compiler looks by default. 如果相关部分安装在默认情况下编译器所看的位置,那么即使这些都是不必要的。 Also these are generally not considered CFLAGS, per se . 而且,这些本身本身通常不被视为CFLAGS。 Terminology varies a bit, but the former is a preprocessor flag, and the latter is a link flag. 术语有所不同,但是前者是预处理器标志,而后者是链接标志。

Since you're using CMake, you could consider writing CMake code to search likely directories for the wanted libraries and headers, and to set the results in suitable variables for other code to use. 由于使用的是CMake,因此可以考虑编写CMake代码以在可能的目录中搜索所需的库和标头,并将结果设置在合适的变量中以供其他代码使用。 That's more of an Autotools-style approach, though. 不过,这更像是一种Autotools风格的方法。 Alternatively, you could define a user-set variable by which the wanted location(s) can be specified to CMake. 另外,您可以定义一个用户设置变量,通过该变量可以将所需位置指定给CMake。 This assumes that the third-party project is not already providing something useful for the purpose. 假设第三方项目尚未为此提供有用的东西。 Or, licensing permitting, you could package the third-party library together with your own, so that you are in control of where it gets installed. 或者,在许可许可的情况下,您可以将第三方库与您自己的库打包在一起,以便您控制其安装位置。

In the general case, however, this is simply something that people have to deal with themselves when they build software. 但是,在一般情况下,这只是人们在构建软件时必须面对的事情。 Make life easier for them by providing good documentation of what your project's dependencies are, and of how to inform the build system of their locations, and make useful provisions for feeding that information into the build system. 通过提供有关项目的依赖项以及如何将其位置告知构建系统的良好文档,并为将信息提供给构建系统提供有用的准备,使他们的工作更轻松。


* An exception could be asserted for use of libtool archives , which an Autotools project might install alongside regular libraries -- if one wanted to use those, they would directly or indirectly go through libtool . *可以断言使用libtool归档文件是一个例外,Autotools项目可以将其与常规库一起安装-如果要使用这些库,它们将直接或间接地通过libtool But in practice, that's only going to happen in another Autotools project. 但是实际上,这只会在另一个Autotools项目中发生。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM