简体   繁体   English

带有子目录的OMake编译

[英]OMake compilation with sub-directories

Looking through OMake documentation it seems whenever sources from subdirectories are used - they are always compiled into static libraries first. 浏览OMake文档,似乎每当使用子目录的源时-始终总是先将它们编译到静态库中。 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. 我一直试图为此编写OMakefiles,但没有成功。

Example dir structure: 目录结构示例:

myproject: OMakeroot, OMakefile, main.cpp myproject:OMakeroot,OMakefile,main.cpp

myproject/headers: file1.h myproject / headers:file1.h

myproject/src: file1.cpp myproject / src:file1.cpp


myproject OMakeroot contents: myproject OMakeroot的内容:

open build/C 打开构建/ C

.SUBDIRS: . .SUBDIRS :。

myproject Omakefile contents: myproject Omakefile的内容:

CXX = g++ CXX = g ++

CXXFLAGS = -Wall CXXFLAGS =-墙

INCLUDES += headers src 包含+ =标头src

CXXProgram(myapp, main file1 ) CXXProgram(myapp,主文件1)


OMakefiles in headers and src directories are empty, not sure if anything needs to be in them. 标头和src目录中的OMakefiles为空,不确定是否需要添加任何内容。

When I run omake myapp I get an error: 运行omake myapp时出现错误:

Do not know how to build "file1.o" required for "myapp" 不知道如何构建“ myapp”所需的“ file1.o”

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). 供以后参考,以防万一线程消失了,这是Maxicat所指线程上发布的解决方案(改写为仅显示解决方案)。

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 包含+ =标头src

INCLUDES is only for the header files. INCLUDES仅适用于头文件。 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.) (注1-前两行的顺序很重要。我编写它的方式,src目录将获得更新的INCLUDES;如果您不希望这样做,请对这两行重新排序。)

(Note2 - the above would expect an src/OMakefile file, even though an empty one would do. You could write something like (注2-上面的代码期望一个src / OMakefile文件,即使一个空文件也可以。您可以编写类似

 .SUBDIRS: src return # A no-op body 

to "inline" the ./src/OMakefile into the ./OMakefile) 将./src/OMakefile“内联”到./OMakefile中)

CXXProgram(myapp, main file1 ) CXXProgram(myapp,主文件1)

Should be 应该

 CXXProgram(myapp, main src/file1) 

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

在Omake邮件列表中已解决此问题,此处仅提供完整性链接以确保完整性: http ://lists.metaprl.org/pipermail/omake/2009-July/002094.html

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

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