简体   繁体   中英

Using the linear algebra library Eigen imported by the workspace in a package

I am using Bazel (version 0.25.2).

I have the following directory structure (one main folder called EigenDemo and a subfolder called Core containing some files):

EigenDemo
|-Core
|  |- BUILD
|  |- main.cpp
|- eigen.BUILD
|- WORKSPACE

The contents of the files look like this:

Core/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

cc_binary(
    name = "EigenDemo",
    srcs = ["main.cpp"],
    copts = ["-Iexternal/eigen"],
    deps = [
        "@eigen",
    ],
)

eigen.BUILD (I use the one provided by tensorflow)

When I try to build ( bazel build //... ) I get the following error:

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:

deps = [
        "@eigen",
    ],

But I do not know how ( "//:eigen" does not work).

Add an empty BUILD file to EigenDemo directory:

EigenDemo
|-Core
|  |- BUILD
|  |- main.cpp
|- BUILD  <-------------------- New empty BUILD file
|- eigen.BUILD
|- WORKSPACE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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