【问题标题】:How to solve libatomic issue in windows?如何解决 Windows 中的 libatomic 问题?
【发布时间】:2019-08-07 10:50:48
【问题描述】:

我正在从 llvm 的源代码开发可执行文件。于是我从github下载了llvm源码。

我正在Windows OS上的命令行尝试一切

我正在关注clang中的libtooling链接

http://clang.llvm.org/docs/LibASTMatchersTutorial.html

我尝试了 2 个选项

选项优先:我运行了以下命令
cmake -G Ninja "C:\Users\amith.ks\Desktop\Clang-llvm\llvm-project\llvm" -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" -DLLVM_BUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Release

一切正常..

第二个选项: 我想从命令行设置cmake_c_compilercmake_cxx_compiler
我不想使用 cmake-gui 所以我运行以下命令
cmake -G Ninja "C:\Users\amith.ks\Desktop\Clang-llvm\llvm-project\llvm" -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" -DLLVM_BUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++

不知从哪里抛出了错误

CMake Error at cmake/modules/CheckAtomic.cmake:53 (message):
  Host compiler appears to require libatomic, but cannot find it.
Call Stack (most recent call first):
  cmake/config-ix.cmake:343 (include)
  CMakeLists.txt:617 (include)

当我看到 cmake 错误日志时,它是这么说的

LINK : fatal error LNK1104: cannot open file 'atomic.lib'

clang: error: linker command failed with exit code 1104 (use -v to see invocation)

ninja: build stopped: subcommand failed.

我搜索了我的整个电脑 atomic.lib 找不到。

如何在 Windows 上解决此问题? 请帮我解答。

【问题讨论】:

    标签: c windows cmake clang llvm


    【解决方案1】:

    我知道它为什么会失败。这是 LLVM 的 cmake 文件中的一个错误。为了检查atomic.lib 是否需要 CheckAtomic.cmake 尝试编译和链接一段代码 atomic.lib。当它失败时(因为atomic.lib 不需要,因此不存在)它错误地断定需要atomic.lib。 LLVM 的 cmake 文件非常混乱,很少修复错误。有虫子在那里呆了很多年。我想这是因为没有人知道 LLVM 构建系统是如何工作的。

    长话短说,我找不到CheckAtomic.cmake 插入atomic.lib 的原因,同时检查它是否不需要。作为一种解决方法,我只是在CheckAtomic.cmake 中无条件地将HAVE_CXX_ATOMICS64_WITHOUT_LIBHAVE_CXX_ATOMICS_WITHOUT_LIB 设置为True

    set(HAVE_CXX_ATOMICS64_WITHOUT_LIB True)
    set(HAVE_CXX_ATOMICS_WITHOUT_LIB True)
    

    【讨论】:

    【解决方案2】:

    使用 clang-cl(或 MSVC cl),它们不需要 lib atomic。

    【讨论】:

      【解决方案3】:

      我正在尝试使用 Clang 11(带有 MSVC ABI)来编译 Clang 11。但是,MSVC 的标头无法在 CheckAtomic.cmake 使用的 C++11 模式下编译:

      set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++11")

      结果:

      C:\Users\nyanpasu\code\llvm-project>clang  -Werror=unguarded-availability-new -std=c++11 uwu.cpp
      In file included from uwu.cpp:1:
      In file included from C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\atomic:19:
      In file included from C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\xatomic.h:13:
      In file included from C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\type_traits:11:
      C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\xstddef:283:22: error: 'auto' return
            without trailing return type; deduced return types are a C++14 extension
      _NODISCARD constexpr auto _Unfancy(_Ptrty _Ptr) noexcept { // converts from a fancy pointer to a plain pointer
                           ^
      1 error generated.
      

      我不知道这是一个 MSVC 错误,它提供了一个与 C++11 不兼容的标头,还是一个 Clang 错误,它使用 MSVC 标头而不是它自己的标头。

      无论如何,将 c++11 更改为 c++14 可以修复此错误。

      【讨论】:

        【解决方案4】:

        正如 lulle 所说,您需要使用正确的工具进行编译。如果您已安装 Visual Studio,请使用 Visual Studio 的开发人员命令提示符而不是常规 cmd,您将拥有所需的环境变量。它位于 Visual Studio 安装目录的 Tools 子目录下。

        例如:

        C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\VsDevCmd.bat

        【讨论】:

          【解决方案5】:

          我在 macOS 中遇到了同样的错误。将 CPP 库添加到路径中为我解决了这个问题。您可以尝试执行以下命令。

          export SDKROOT="$(xcrun --sdk macosx --show-sdk-path)"
          
          export CPLUS_INCLUDE_PATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2021-12-06
            • 1970-01-01
            • 2016-01-07
            • 2019-01-09
            • 1970-01-01
            • 2021-02-06
            • 1970-01-01
            • 2015-12-04
            相关资源
            最近更新 更多