首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在Windows 10和VisualStudioCommunity2019下使用boost和Bazel

在Windows 10和VisualStudioCommunity2019下使用boost和Bazel
EN

Stack Overflow用户
提问于 2019-05-07 20:02:54
回答 1查看 868关注 0票数 6

我已经设置了一个使用boost文件系统模块的简单C++程序。要构建程序,我使用Bazel0.25.0。我是在Windows 10 x64下工作的。我安装了VisualStudio2019社区编辑,并将BAZEL_VC设置为E:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC。我已经安装了MSYS2外壳。

以下是我的文件(也可以在GitHub上找到):

工作空间

代码语言:javascript
运行
复制
workspace(name = "BoostFilesystemDemo")

load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

# Boost
git_repository(
    name = "com_github_nelhage_rules_boost",
    commit = "6681419da0163d097d4e09c0756c0d8b785d2aa8",
    remote = "https://github.com/nelhage/rules_boost",
    shallow_since = "1556401984 -0700"
)

load("@com_github_nelhage_rules_boost//:boost/boost.bzl", "boost_deps")
boost_deps()

main.cpp

代码语言:javascript
运行
复制
#include <iostream>
#include <boost/filesystem.hpp>

using namespace boost::filesystem;

int main(int argc, char* argv[])
{
    if (argc < 2)
    {
        std::cout << "Usage: tut1 path\n";
        return 1;
    }
    std::cout << argv[1] << " " << file_size(argv[1]) << '\n';
    return 0;
}

构建

代码语言:javascript
运行
复制
cc_binary(
    name = "FilesystemTest",
    srcs = ["main.cpp"],
    deps = [
            "@boost//:filesystem",
    ],
)

当我试图构建时,我会收到以下错误消息(不幸的是,它混合了一些德语- Datei kann nicht gefunden werden意思是file not found)

代码语言:javascript
运行
复制
PS E:\dev\BazelDemos\BoostFilesystemDemo> bazel build //...
INFO: Analyzed target //:FilesystemTest (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
ERROR: E:/dev/bazeldemos/boostfilesystemdemo/BUILD:1:1: Linking of rule '//:FilesystemTest' failed (Exit 1104)
LINK : fatal error LNK1104: Datei "libboost_filesystem-vc141-mt-x64-1_68.lib" kann nicht ge÷ffnet werden.
Target //:FilesystemTest failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 1.175s, Critical Path: 0.12s
INFO: 0 processes.
FAILED: Build did NOT complete successfully

有人想解决这个问题吗(用Bazel0.25.0或更高版本编译源代码,VisualStudio2019社区版,Windows10 x64,目标应该是x64)吗?使用Ubuntu18.04,一切都很好。

切换到另一个提供boost的git存储库对我来说也不错。

我还想使用boost库的其他部分,如boost signals2、boost日志、boost算法和boost compute。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-05-14 19:31:27

以这种方式修改BUILD.boost

代码语言:javascript
运行
复制
diff --git a/BUILD.boost b/BUILD.boost
index a3a2195..2cffdda 100644
--- a/BUILD.boost
+++ b/BUILD.boost
@@ -623,6 +623,14 @@ boost_library(
         ":system",
         ":type_traits",
     ],
+    defines = select({
+        ":linux_arm": [],
+        ":linux_x86_64": [],
+        ":osx_x86_64": [],
+        ":windows_x86_64": [
+            "BOOST_ALL_NO_LIB",
+        ],
+    }),
 )

 boost_library(
@@ -1491,6 +1499,14 @@ boost_library(
         ":predef",
         ":utility",
     ],
+    defines = select({
+        ":linux_arm": [],
+        ":linux_x86_64": [],
+        ":osx_x86_64": [],
+        ":windows_x86_64": [q
+            "BOOST_ALL_NO_LIB",

我克隆了rules_boost回购并应用了上述更改--可以在工作区文件中使用克隆的存储库:

代码语言:javascript
运行
复制
workspace(name = "BoostFilesystemDemo")

load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

# Boost
git_repository(
    name = "com_github_nelhage_rules_boost",
    commit = "f0d2a15d6dd5f0667cdaa6da9565ccf87b84c468",
    remote = "https://github.com/Vertexwahn/rules_boost",
    shallow_since = "1557766870 +0200"
)

load("@com_github_nelhage_rules_boost//:boost/boost.bzl", "boost_deps")
boost_deps()

目前,正在运行一个拉请求将这些更改合并到原始存储库:助推/拉动/123

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56029731

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档