Automake 生成二​​进制文件到 bin/ 而不是 src/

发布于 2024-08-19 05:10:16 字数 338 浏览 5 评论 0原文

我搜索了这个问题的答案,但找不到任何好的答案。也许他们老了,有些事情发生了变化,所以我再问一遍。

我的目录结构为:

my_project

  • src

  • bin

我希望,当我在根目录中 make 时,二进制文件放在 ./bin 中,而不是混乱./src.但如何呢?

编辑:我正在使用 C++。我的 Makefile.am 没有什么特别的。只是 bin_PROGRAM 和 _SOURCES 变量。

当我运行 make 时,生成的二进制文件被放入 ./src 中。我只想将它们放在 ./bin 中。

I searched for the answer to this question but couldn't find any good. Maybe they're old and something has changed, so I ask again.

I have a directory structure as:

my_project

  • src

  • bin

I want that, when I do make in the root dir, the binaries are put in ./bin, instead of cluttering ./src. But how?

EDIT: I am using C++. My Makefile.am has nothing special. Just the bin_PROGRAM and _SOURCES variables.

When I run make, the binaries generated are put into ./src. I simply want them in ./bin.

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

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

发布评论

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

评论(3

昔日梦未散 2024-08-26 05:10:16

你在这里有错误的想法。

您的构建树位于您运行 configure 的位置。这就是 autoconf 的工作原理。您的包的用户(不想弄乱他们的源代码树)将期望它以这种方式工作。

这种方法是一种更通用的解决方案,比您想象的组织具有更大的灵活性。例如,想要在单独的文件系统上维护源代码和构建文件并不罕见。

You've got the wrong idea here.

Your build tree is wherever you run configure. That's how autoconf is designed to work. Users of your package (who do not want to clutter their source tree) will expect it to work this way.

This approach is a more general solution with a lot more flexibility than the organization you're imagining. For instance, it's not terribly unusual to want to maintain sources and build files on separate filesystems.

静若繁花 2024-08-26 05:10:16

如果您尝试以与预期不同的方式设置目录,Automake 将无法很好地应对。您想要的将涉及编写额外的规则以在编译后将二进制文件移动到 ../bin ,这是不必要的复杂。

如果您不想弄乱源目录,请尝试以下操作:

cd my_project
mkdir build
cd build
../configure
make

这会将所有生成的文件(如 makefile、二进制文件、目标文件)放入 my_project/build 的子目录中。

Automake doesn't cope very well if you try to set up your directories in a different way than it expects. What you want would involve writing extra rules to move the binaries to ../bin after compiling them, which is needlessly complicated.

If you don't want to clutter your source directory, try this:

cd my_project
mkdir build
cd build
../configure
make

That will put all the generated files (like makefiles, binaries, object files) in subdirectories of my_project/build.

粉红×色少女 2024-08-26 05:10:16

告诉 Automake 在某个目录中创建二进制文件的一种方法是将此目录添加到“bin_PROGRAMS”变量中的名称右侧。

考虑以下 src/Makefile.am:

bin_PROGRAMS = foo
foo_SOURCES = ...
foo_CPPFLAGS = ...
foo_LDFLAGS = ...

它创建一个二进制“src/foo”,但您可以告诉 Automake 使用 src 中的源来创建一个二进制“bin/foo”:

bin_PROGRAMS = $(top_builddir)/bin/foo
__top_builddir__bin_foo_SOURCES = ...
__top_builddir__bin_foo_CPPFLAGS = ...
__top_builddir__bin_foo_LDFLAGS = ...

我尝试使用一些包,甚至“make distcheck”吞掉了它。但不可能有那么大的黑客......

One way to tell Automake to create binaries in a certain directory is to add this directory right to the name in the "bin_PROGRAMS" variable.

Consider the following src/Makefile.am:

bin_PROGRAMS = foo
foo_SOURCES = ...
foo_CPPFLAGS = ...
foo_LDFLAGS = ...

It creates a binary "src/foo", but you can tell Automake to use the sources in src to create a binary "bin/foo":

bin_PROGRAMS = $(top_builddir)/bin/foo
__top_builddir__bin_foo_SOURCES = ...
__top_builddir__bin_foo_CPPFLAGS = ...
__top_builddir__bin_foo_LDFLAGS = ...

I tried it with some packages and even "make distcheck" swallows it. Can't be that much of a hack though...

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