带子目录的 OMake 编译

发布于 2024-07-26 07:54:47 字数 689 浏览 10 评论 0原文

查看 OMake 文档,似乎每当使用子目录中的源时 - 它们总是首先编译成静态库。 这总是必要的吗? 我可以在不构建库的情况下编译和链接所有内容吗? 我一直在尝试为此编写 OMakefiles 但没有成功。

示例目录结构:

myproject: OMakeroot, OMakefile, main.cpp

myproject/headers: file1.h

myproject/src: file1.cpp


myproject OMakeroot 内容:

open build/C

。子目录: .

myproject Omakefile 内容:

CXX = g++

CXXFLAGS = -Wall

INCLUDES += headers src

CXXProgram(myapp, main file1 )


headers 和 src 目录中的 OMakefiles 为空,不确定其中是否需要任何内容​​。

当我运行 omake myapp 时,出现错误:

不知道如何构建“myapp”所需的“file1.o”

Looking through OMake documentation it seems whenever sources from subdirectories are used - they are always compiled into static libraries first. Is this always necessary? Can I compile and link everything without building the libs? I've been trying to write OMakefiles for this but with no success.

Example dir structure:

myproject: OMakeroot, OMakefile, main.cpp

myproject/headers: file1.h

myproject/src: file1.cpp


myproject OMakeroot contents:

open build/C

.SUBDIRS: .

myproject Omakefile contents:

CXX = g++

CXXFLAGS = -Wall

INCLUDES += headers src

CXXProgram(myapp, main file1 )


OMakefiles in headers and src directories are empty, not sure if anything needs to be in them.

When I run omake myapp I get an error:

Do not know how to build "file1.o" required for "myapp"

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

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

发布评论

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

评论(3

世界和平 2024-08-02 07:54:47

为了将来参考,以防线程消失,这里是 Maxicat 引用的线程上发布的解决方案(经过重新措辞以仅显示解决方案)。

情况并非必须编译成静态库,但是
默认假设是每个目标文件进入相同的
目录作为源文件。

包括 += 标头 src

INCLUDES 仅适用于头文件。 你需要

包括 += $(dir headers) 
  .子目录:src 
  

(注1 - 前两行的顺序很重要。我的方式
编写它,src 目录将获得更新的 INCLUDES; 如果你不想
那,重新排序两者。)

(注 2 - 上面的内容需要一个 src/OMakefile 文件,即使
空一个就可以了。 你可以写类似的东西

<前><代码>.SUBDIRS:src
return # 一个无操作体

将 ./src/OMakefile“内联”到 ./OMakefile)

CXXProgram(myapp, 主文件1)

应该是

CXXProgram(myapp, main src/file1) 
  

For future reference, in case the thread disappears, here is the solution posted on the thread that Maxicat refers to (reworded to show just the solution).

It is not the case that you have to compile into static libraries, but
the default assumption is that each object file goes into the same
directory as the source file.

INCLUDES += headers src

INCLUDES is only for the header files. You need

INCLUDES += $(dir headers)
.SUBDIRS: src

(Note1 - the order of the previous two lines is important. The way I
wrote it, the src dir would get the updated INCLUDES; if you do not want
that, reorder the two.)

(Note2 - the above would expect an src/OMakefile file, even though an
empty one would do. You could write something like

.SUBDIRS: src
   return # A no-op body

to "inline" the ./src/OMakefile into the ./OMakefile)

CXXProgram(myapp, main file1 )

Should be

CXXProgram(myapp, main src/file1)
自在安然 2024-08-02 07:54:47

尝试 src/file1,以便 omake 知道它需要构建 src/file1.o 而不是 file1.o,因此需要 < code>src/file1.cpp 而不是 file1.cpp (它不存在)。

Try src/file1, so that omake knows that it needs to build src/file1.o instead of file1.o, and therefore needs src/file1.cpp instead of file1.cpp (which doesn't exist).

自由如风 2024-08-02 07:54:47

在 Omake 邮件列表上解决了这个问题,为了完整性,这里的线程链接: http://lists.metaprl.org/pipermail/omake/2009-July/002094.html

Got this resolved on the Omake mailing list, thread link here just for completeness: http://lists.metaprl.org/pipermail/omake/2009-July/002094.html

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