[英]Using the linear algebra library Eigen imported by the workspace in a package
I am using Bazel (version 0.25.2). 我正在使用Bazel (0.25.2版)。
I have the following directory structure (one main folder called EigenDemo
and a subfolder called Core
containing some files): 我具有以下目录结构(一个名为
EigenDemo
主文件夹和一个名为Core
的子文件夹,其中包含一些文件):
EigenDemo
|-Core
| |- BUILD
| |- main.cpp
|- eigen.BUILD
|- WORKSPACE
The contents of the files look like this: 文件的内容如下所示:
Core/main.cpp 核心/ main.cpp中
#include <iostream>
#include <Eigen/Dense>
using Eigen::MatrixXd;
int main()
{
MatrixXd m(2, 2);
m(0, 0) = 3;
m(1, 0) = 2.5;
m(0, 1) = -1;
m(1, 1) = m(1, 0) + m(0, 1);
std::cout << m << std::endl;
}
WORKSPACE 工作区
workspace(name = "EigenDemo")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
# Eigen
http_archive(
name = "eigen",
build_file = "//:eigen.BUILD",
sha256 = "3a66f9bfce85aff39bc255d5a341f87336ec6f5911e8d816dd4a3fdc500f8acf",
url = "https://bitbucket.org/eigen/eigen/get/c5e90d9.tar.gz",
strip_prefix="eigen-eigen-c5e90d9e764e"
)
Core/BUILD 核心/ BUILD
cc_binary(
name = "EigenDemo",
srcs = ["main.cpp"],
copts = ["-Iexternal/eigen"],
deps = [
"@eigen",
],
)
eigen.BUILD (I use the one provided by tensorflow) eigen.BUILD (我使用tensorflow提供的那个)
When I try to build ( bazel build //...
) I get the following error: 当我尝试构建(
bazel build //...
)时,出现以下错误:
PS E:\dev\BazelDemos\EigenDemo> bazel build //...
Starting local Bazel server and connecting to it...
INFO: An error occurred during the fetch of repository 'eigen'
INFO: Call stack for the definition of repository 'eigen':
- E:/dev/bazeldemos/eigendemo/WORKSPACE:6:1
INFO: Repository 'eigen' used the following cache hits instead of downloading the corresponding file.
* Hash '3a66f9bfce85aff39bc255d5a341f87336ec6f5911e8d816dd4a3fdc500f8acf' for https://bitbucket.org/eigen/eigen/get/c5e90d9.tar.gz
If the definition of 'eigen' was updated, verify that the hashes were also updated.
ERROR: E:/dev/bazeldemos/eigendemo/Core/BUILD:1:1: no such package '@eigen//': Traceback (most recent call last):
File "C:/users/admin/_bazel_admin/u7yxnnij/external/bazel_tools/tools/build_defs/repo/http.bzl", line 56
workspace_and_buildfile(ctx)
File "C:/users/admin/_bazel_admin/u7yxnnij/external/bazel_tools/tools/build_defs/repo/utils.bzl", line 64, in workspace_and_buildfile
ctx.symlink(ctx.attr.build_file, "BUILD.bazel")
Unable to load package for //:eigen.BUILD: BUILD file not found in any of the following directories.
- E:/dev/bazeldemos/eigendemo and referenced by '//Core:EigenTest'
ERROR: Analysis of target '//Core:EigenTest' failed; build aborted: no such package '@eigen//': Traceback (most recent call last):
File "C:/users/admin/_bazel_admin/u7yxnnij/external/bazel_tools/tools/build_defs/repo/http.bzl", line 56
workspace_and_buildfile(ctx)
File "C:/users/admin/_bazel_admin/u7yxnnij/external/bazel_tools/tools/build_defs/repo/utils.bzl", line 64, in workspace_and_buildfile
ctx.symlink(ctx.attr.build_file, "BUILD.bazel")
Unable to load package for //:eigen.BUILD: BUILD file not found in any of the following directories.
- E:/dev/bazeldemos/eigendemo
INFO: Elapsed time: 10.959s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (9 packages loaded, 33 targets configured)
When I place all files in one folder everything works fine. 当我将所有文件放在一个文件夹中时,一切正常。 I guess I have to change the
deps
field in the BUILD file: 我想我必须更改BUILD文件中的
deps
字段:
deps = [
"@eigen",
],
But I do not know how ( "//:eigen"
does not work). 但是我不知道如何(
"//:eigen"
不起作用)。
Add an empty BUILD file to EigenDemo
directory: 将一个空的BUILD文件添加到
EigenDemo
目录:
EigenDemo
|-Core
| |- BUILD
| |- main.cpp
|- BUILD <-------------------- New empty BUILD file
|- eigen.BUILD
|- WORKSPACE
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.