简体   繁体   English

在 bazel 项目中包含本地构建的非 bazel c++ 库

[英]Include a locally built non bazel c++ library in bazel project

I'm new to bazel and c++ development.我是 bazel 和 c++ 开发的新手。 I have a similar situation as posted in here and here .我的情况与此处此处发布的情况类似。 Followed the steps posted in the first link,where I'm trying to load this locally built package into a bazel project.按照第一个链接中发布的步骤,我正在尝试将这个本地构建的 package 加载到 bazel 项目中。

WORKSPACE

new_local_repository(
    name = "openvino",
    build_file = "backend/cpp/BUILD",
    path = "C:\\Users\\user\\OpenVINO2022.1.0.dev20220316_OMP\\openvino",
)

BUILD file inside backend/cpp folder在 backend/cpp 文件夹中BUILD文件

cc_library(
    name = "openvino",
    srcs = glob(["**/*.lib"])+ glob(["**/*.dll"]),
    hdrs = glob(["**/*.hpp"]),
    includes = ["src/inference/include/openvino"],
    visibility = ["//visibility:public"]
)

cc_library(
    name = "main_c",
    srcs = ["main_c.cc"],
    hdrs = [
        "utils.h",
    ],
    deps = [
        "//flutter/cpp/c:headers",
    ],
    alwayslink = 1,
    visibility = ["//visibility:public"]
)

cc_binary(
    name = "libbackend.dll",
    linkshared = 1,
    win_def_file = "//flutter/cpp/c:dll_export.def",
    deps = [
        ":openvino",
        ":main_c",
    ],
     linkopts = ["-shared"],
)

main_c.cc file in backend/cpp folder后端/cpp 文件夹中的 main_c.cc 文件

#include "openvino\src\inference\include\openvino\openvino.hpp"

But I'm still not able to load this library.但我仍然无法加载这个库。

Error错误

backend/cpp/main_c.cc(7): fatal error C1083: Cannot open include file: 'openvino\src\inference\include\openvino\openvino.hpp': No such file or directory

Any help is appreciated.任何帮助表示赞赏。

This seems to be an issue with your include paths.这似乎是您的包含路径的问题。 The include path to your header should be. header 的包含路径应​​该是。

#include "src\inference\include\openvino\openvino.hpp"

Or as you've added includes = ["src/inference/include/openvino"] to your 'openvino' target you could also use the include path.或者,当您将includes = ["src/inference/include/openvino"]添加到您的 'openvino' 目标时,您也可以使用包含路径。

#include "openvino.hpp"

If for some reason you need to keep your include path the same you can add an include prefix to your 'openvino' target.如果由于某种原因您需要保持包含路径相同,您可以在“openvino”目标中添加包含前缀。

eg例如

cc_library(
    name = "openvino",
    srcs = glob(["**/*.lib"])+ glob(["**/*.dll"]),
    hdrs = glob(["**/*.hpp"]),
    # Remove this line.
    # includes = ["src/inference/include/openvino"],
    
    # Add this line, to allow include as if it were in an "openvino"
    # directory.
    include_prefix = "openvino",
    visibility = ["//visibility:public"]
)

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

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