【问题标题】:Using boost with Bazel under Windows 10 and Visual Studio Community 2019在 Windows 10 和 Visual Studio Community 2019 下使用带有 Bazel 的 boost
【发布时间】:2019-09-25 12:53:56
【问题描述】:

我已经建立了一个使用 boost 文件系统模块的简单 C++ 程序。为了构建程序,我使用 Bazel 0.25.0。我在 Windows 10 x64 下工作。 我安装了 Visual Studio 2019 Community Edtion 并将BAZEL_VC 设置为E:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC。我已经安装了 MSYS2 shell。

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

工作空间

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

#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;
}

构建

cc_binary(
    name = "FilesystemTest",
    srcs = ["main.cpp"],
    deps = [
            "@boost//:filesystem",
    ],
)

当我尝试构建时,我收到以下错误消息(不幸的是与一些德语混合 - Datei kann nicht gefunden werden 表示 file not found

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

有没有人想办法解决这个问题(使用 Bazel 0.25.0 或更高版本编译源代码,Visual Studio 2019 社区版,Windows 10 x64,目标应该是 x64)?使用 Ubuntu 18.04 一切正常。

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

我还想使用 boost 库的其他部分,例如 boost signals2、boost log、boost algorithm 和 boost compute。

【问题讨论】:

  • 您的 MSVC 版本是多少?我可以使用 VC 14.0 (Visual Studio 2015) 进行编译。我在运行 Bazel 之前set BAZEL_VC=c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC。但是我的构建失败并出现链接错误 (LINK : fatal error LNK1104: cannot open file 'libboost_filesystem-vc140-mt-x64-1_68.lib')。
  • @László:我切换到 VS 2019 并更新了我的问题。现在,我有同样的错误(vc141 而不是 vc140)
  • 你能发布你的编译步骤的输出并添加--verbose_failures标志吗?它可以帮助我们诊断问题,而无需重现您的设置。
  • -1:提供赏金并且自己没有做任何事情。您是否寻找以下内容:1. lib 文件确实存在,2. 如果是,那么它不是一些访问限制(如果可以,请尝试提升运行)? 3.不是某个地方定义的路径变量爆炸了吗? (检查实际使用的路径,即检查搜索路径)
  • 您或许可以通过使用&lt;filesystem&gt; 而不是&lt;boost/filesystem.hpp&gt; 来避开这个问题。

标签: c++ windows boost bazel visual-studio-2019


【解决方案1】:

这样修改BUILD.boost

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 存储库并应用了上述更改 - 克隆的存储库可以直接在 WORKSPACE 文件中使用:

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()

目前,正在运行拉取请求以将这些更改合并到原始存储库中:https://github.com/nelhage/rules_boost/pull/123

【讨论】:

    猜你喜欢
    • 2020-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-06
    • 1970-01-01
    • 2020-04-16
    • 1970-01-01
    • 2021-08-10
    相关资源
    最近更新 更多