简体   繁体   English

Meson和Eigen的文件路径问题

[英]File path issue with Meson and Eigen

I cannot make local include paths work in the Meson build system. 我不能让本地包含路径在Meson构建系统中工作。

This C++ inclusion works correctly: 此C ++包含正常工作:

#include </cygdrive/c/Users/user/project/Third-Party/eigen/Eigen/Dense>

This one does not: 这个没有:

#include "Third-Party/eigen/Eigen/Dense"

fatal error: Eigen/Dense: No such file or directory 致命错误:Eigen / Dense:没有这样的文件或目录

In the Meson build file, I tried to add Eigen's path, without success: 在Meson构建文件中,我试图添加Eigen的路径,但没有成功:

# '.' will refer to current build directory
include_dirs = include_directories('include', '.', '../project/Third-Party/eigen')

This is the project tree structure: 这是项目树结构:

project
   meson.build
   src
      meson.build
      example.h
      example.cpp
   Third-Party
      eigen  (headers only lib)
         Eigen

Note: with CMake I do not have this issue. 注意:使用CMake我没有这个问题。

For dependency management, meson allows you to manually declare include_directories() in your build files. 对于依赖关系管理,介子允许您在构建文件中手动声明include_directories() However, there is another way do handle dependencies: using dependency() command. 但是,还有另一种处理依赖关系的方法:使用dependency()命令。

dependency() is a much better way to handle dependencies, because meson will build it if necessary (if dependency is a shared or a static library) and safely allows you to use includes. dependency()是一种更好的处理依赖关系的方法,因为meson将在必要时构建它(如果依赖是共享或静态库)并且安全地允许您使用包含。 That means that you don't have to know where includes for dependency are located physically or care about their paths ever after. 这意味着您不必知道依赖项的物理位置在哪里,也不必关心其路径。 The only downside is that this kind of dependency needs it's own meson.build file. 唯一的缺点是这种依赖需要它自己的meson.build文件。

Using dependency() command: 使用dependency()命令:

To actually use it, you have to write a wrap file for dependency. 要实际使用它,您必须编写一个依赖包装文件 Or, if you are lucky enough, there is already a wrap file for you in the Wrap DB -- a community-driven database for meson wrap files. 或者,如果你足够幸运,在Wrap DB中已经存在一个包装文件 - 一个用于介子包装文件的社区驱动数据库。 Wrap file is a config of some kind that declare where you can get a dependency and in what form. 换行文件是某种类型的配置,它声明了哪里可以获得依赖关系以及以何种形式。 Wrap file can wrap around zip archives and git repositories. 换行文件可以包装zip存档和git存储库。

For your given dependency, there is wrap file in Wrap DB: eigen . 对于您的给定依赖项,Wrap DB中包含文件: eigen All you have to do is download it and place it in the subprojects directory near your meson.build . 您所要做的就是下载它并将其放在meson.build附近的subprojects目录中。 For example: 例如:

$ cd project
$ mkdir subprojects
$ wget "https://wrapdb.mesonbuild.com/v1/projects/eigen/3.3.4/1/get_wrap" \
  -O subprojects/eigen.wrap

Now, not every project builds with meson. 现在,并非每个项目都使用介子构建。 For the ones that don't, wrap file also specify a patch . 对于那些没有的,wrap文件也指定一个补丁 Patch is used to just copy appropriate meson.build file into dependency directory (as well as any other files that would be needed for building that particular dependency with meson). 补丁用于将适当的meson.build文件复制到依赖目录(以及使用介子构建特定依赖关系所需的任何其他文件)。 Eigen wrap file contains a patch. 特征包装文件包含一个补丁。

To find out how any particular dependency declare itself as a dependency (using declare_dependency() command), you need to investigate meson.build file in dependency source directory (although it's often just name of the dependency plus _dep , eg "eigen_dep"). 要了解任何特定依赖项如何将自身声明为依赖项(使用declare_dependency()命令),您需要调查依赖项源目录中的meson.build文件(尽管它通常只是依赖项加上_dep的 名称 ,例如“eigen_dep”)。 For me, eigen directory was subprojects/eigen-eigen-5a0156e40feb . 对我来说, 特征目录是subprojects/eigen-eigen-5a0156e40feb So, you search for the declare_dependency() command: 因此,您搜索declare_dependency()命令:

$ grep declare_dependency subprojects/eigen-eigen-5a0156e40feb/meson.build
eigen_dep = declare_dependency(

As you can see, eigen declare dependency as eigen_dep . 如您所见,eigen声明依赖为eigen_dep If you want to know what exactly is declared, just scroll down the dependency meson.build file. 如果您想知道究竟是什么声明,只需向下滚动依赖meson.build文件。

Now, to use that eigen_dep in your project, create a dependency object with a dependency() command. 现在,要在项目中使用该eigen_dep ,请使用dependency()命令创建依赖项对象。 Here is a sample project that I used to compile "A simple first program" from Eigen: Getting Started : 这是一个示例项目,我用来编译Eigen的 “简单的第一个程序” :入门

project('example', 'cpp')
eigen_dependency = dependency('eigen', fallback: ['eigen', 'eigen_dep'])
executable('example', 'example.cpp', dependencies: eigen_dependency) 

Notice arguments for the dependency() command. 请注意dependency()命令的参数。 The first one is system-wide dependency that meson is searching for. 第一个是介子正在搜索的系统范围的依赖。 If there is no eigen for development installed in your system, then meson uses fallback : first item in fallback is basename of the wrap file, second item is a name of declared dependency. 如果你的系统中没有安装了开发的特征 ,则meson使用fallbackfallback中的第一项是wrap文件的basename,第二项是声明的依赖项的名称。

Then use eigen_dependency variable in whatever you build, passing it to the dependencies argument. 然后在构建的任何内容中使用eigen_dependency变量,并将其传递给dependencies参数。

Using include_directories() command: 使用include_directories()命令:

If you want to just include some files from external directory (such as your "Third-Party" directory) using include_directories() command, that directory has to be relative to the meson.build file where you use it. 如果您只想使用include_directories()命令从外部目录(例如“第三方”目录)中包含一些文件,则该目录必须与您使用它的meson.build文件相关。

To use manually declared includes, you need to call include_directories() command to get the include_directories object. 要使用手动声明的包含,需要调用include_directories()命令来获取include_directories对象。 Pass that object to include_directories argument in whatever you build. 在您构建的任何内容中将该对象传递给include_directories参数。

Given your example, I assume that root meson.build file is a project build file. 举个例子,我假设root meson.build文件是一个项目构建文件。 Then in that root meson.build , for example, you can write: 然后在那个根meson.build ,例如,你可以写:

# File: project/meson.build
project('example', 'cpp')
eigen_includes = include_directories('Third-Parties/eigen')
executable('example', 'example.cpp', include_directories: eigen_includes)

But if you want to get eigen includes from src/meson.build , then you need to change include_directories to: 但是如果你想从src/meson.build获得eigen包含,那么你需要将include_directories更改为:

# File: project/src/meson.build
eigen_includes = include_directories('../Third-Parties/eigen')
...

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

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