使用 autoconf/automake,如何指定包含文件路径?

发布于 2024-12-05 12:41:03 字数 413 浏览 1 评论 0原文

假设我想让生成 makefile 将一些特定的头路径传递给 g++。

我需要在configure.ac或Makefile.am中添加什么来指定这一点?

(注意 - 我不想用 ./configure 将其传递到 CPPFLAGS 中。我希望在该步骤之前烘焙这些路径)

编辑: 具体来说,我想包括 /usr/include/freetype 和 /mypath/include。

我放入 AC_CHECK_HEADERS([freetype/config/ftheader.h]) 并且它通过了,但似乎没有将其添加到 -I 传递给 g++ 中。

我也尝试添加 CPPFLAGS=-I.:/usr/include/freetype:/mypath/include ,但它搞砸了并将 -I 两次,第一次作为 -I 。它忽略了第二个 -I。

Let's say I want to have the generate makefile pass some specific header paths to g++.

What do I need to add to configure.ac or Makefile.am to specify this?

(note - I do not want to pass it in the CPPFLAGS with ./configure. I want those paths baked in before that step)

EDIT:
Specifically, I want to to include let's say /usr/include/freetype and /mypath/include.

I put AC_CHECK_HEADERS([freetype/config/ftheader.h]) and it passes, but doesn't seem to add it to the -I passed to g++.

I also did try adding CPPFLAGS=-I.:/usr/include/freetype:/mypath/include, but it screws up and puts -I twice, the first as -I. and it ignores the 2nd -I.

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

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

发布评论

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

评论(2

み青杉依旧 2024-12-12 12:41:03

由于问题是关于在 automakefile 中放入什么内容,我认为 AM_CPPFLAGS 是用于为所有 C/C++ 编译添加包含和定义的正确变量。请参阅 http://www.gnu.org/software/automake/ Manual/html_node/Program-Variables.html

示例:

AM_CPPFLAGS = -I/usr/local/custom/include/path

Since the question was about what to put in an automakefile, I would have thought AM_CPPFLAGS was the right variable to use to add includes and defines for all C/C++ compiles. See http://www.gnu.org/software/automake/manual/html_node/Program-Variables.html

Example:

AM_CPPFLAGS = -I/usr/local/custom/include/path
撞了怀 2024-12-12 12:41:03

将路径硬编码到包文件中绝对是错误的做法。如果您选择这样做,那么您需要意识到您违反了使用自动工具构建包的基本规则。如果您在包文件中指定 /mypath/include ,则您将在一个适用于所有计算机的包中指定特定于您的计算机的内容;显然这是错误的。看起来您想要的是让您的包(在您的计算机上构建时)在 /mypath 中查找头文件。这很容易实现,无需破坏你的包。有(至少)3 种方法可以做到这一点:

  1. 使用 config.site 文件。在 /usr/local/share/config.site(如有必要,创建此文件)中,添加以下行:

    CPPFLAGS="$CPPFLAGS -I/mypath/include"
    

    现在,任何使用 autoconf 生成的带有默认前缀 (/usr/local) 的配置脚本的包都会将 -I/mypath/include 附加到 CPPFLAGS< /code> 和 /mypath/include 中的标头将被找到。

  2. 如果您希望为所有构建进行分配(而不仅仅是那些安装在 /usr/local 中的构建),您可以使用以下命令:

    $HOME/config.site 中放置指定 CPPFLAGS 的同一行,并在默认 shell 的环境。现在,每当您运行 autoconf 生成的配置脚本时,都会从 $HOME/config.site 进行分配。

  3. 只需在默认 shell 环境中指定 CPPFLAGS

与修改构建文件相比,所有这些解决方案都有两个主要优点。首先,它们适用于所有 autoconf 生成的包(只要它们遵循规则并且不执行诸如在构建文件中分配诸如 CPPFLAGS 之类的用户变量之类的操作)。其次,他们不会将您的计算机特定信息放入应在所有计算机上运行的包中。

Hard coding paths into the package files is absolutely the wrong thing to do. If you choose to do that, then you need to be aware that you are violating the basic rules of building a package with the autotools. If you specify /mypath/include in your package files, you are specifying things specific to your machine in a package that is intended to work on all machines; clearly that is wrong. It looks like what you want is for your package (when built on your machine) to look for header files in /mypath. That is easy to accomplish without bastardizing your package. There are (at least) 3 ways to do it:

  1. Use a config.site file. In /usr/local/share/config.site (create this file if necessary), add the line:

    CPPFLAGS="$CPPFLAGS -I/mypath/include"
    

    Now any package using an autoconf generated configure script with the default prefix (/usr/local) will append -I/mypath/include to CPPFLAGS and the headers in /mypath/include will be found.

  2. If you want the assignment to be made for all builds (not just those to be installed in /usr/local), you can use this:

    Put the same line specifying CPPFLAGS in $HOME/config.site, and set CONFIG_SITE=$HOME/config.site in the environment of your default shell. Now, whenever you run an autoconf generated configure script, the assignments from $HOME/config.site will be made.

  3. Simply specify CPPFLAGS in the environment of your default shell.

All of these solutions have two primary advantages over modifying your build files. First, they will work for all autoconf generated packages (as long as they follow the rules and don't do things like assigning user variables such as CPPFLAGS in the build files). Second, they do not put your machine specific information into a package that ought to work on all machines.

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