【问题标题】:Conan does not detect MinGW gcc柯南没有检测到MinGW gcc
【发布时间】:2020-08-10 23:27:32
【问题描述】:

Conan 在创建包时不会自动检测 MinGW 编译器。请参考以下错误:

Configuration:
[settings]
arch=x86_64
arch_build=x86_64
build_type=Release
os=Windows
os_build=Windows
[options]
[build_requires]
[env]

ERROR: : 'settings.compiler' value not defined

【问题讨论】:

    标签: conan


    【解决方案1】:

    解决方案 1

    您可以使用 conan 开发包安装 msys2 或 mingw64。

    柯南已经设置了一些你可以通过 build requires 克隆的 bin。这些工作就像先决条件一样,这意味着任何使用柯南配置文件的机器都将安装它们。这意味着您将在您的柯南包(home/.conan/data/blah blah)中获得另一个自容器mingw和msys。

    [build_requires]
    mingw_installer/1.0@conan/stable
    msys2/20190524
    
    [settings]
    os_build=Windows
    os=Windows
    arch=x86_64
    arch_build=x86_64
    compiler=gcc
    compiler.version=4.9
    compiler.libcxx=libstdc++11
    compiler.threads=posix
    build_type=Release
    

    感谢 AvadhanaSolutions

    解决方案 2

    不工作的原因是不仅需要为gcc,g++设置工具链,还需要定义目标和生成器。柯南和 cmake 都需要清楚这一点。在这种情况下,cmake 找不到这些工具链。

    鉴于 mingw 和 msys 二进制文件的推荐安装位置不要放在“程序文件”中。安装位置因人而异。鉴于这种可变性,我们需要确保两件事来生成成功的构建。以下不仅适用于 gcc,也适用于其他工具,如 clang

    步骤

    1. 查找 gcc、g++ 的路径,并为您的机器制作。
      (注意确保您有全名)

      #!/bin/bash
      echo "Find Gcc,G++ and mingw make then append these to a conan profile"
      which gcc 
      which g++
      which make
      

      这会返回类似的东西

      /c/msys64/mingw64/bin/gcc 
      /c/msys64/mingw64/bin/g++ 
      /c/msys64/usr/bin/make    
      
    2. 将环境变量添加到柯南安装配置文件。
      (即我的柯南文件有)

      [env]
      CC=C:/msys64/mingw64/bin/gcc
      CXX=C:/msys64/mingw64/bin/g++
      
    3. 为 Cmake 定义生成器。在这里,我们需要设置等效于 CMake 命令cmake .. -G "MinGW Makefiles。默认情况下,柯南使用 Unix Makefiles,除非您正在运行的窗口;)然后它只使用任何 cmake 应用作为默认生成器。因此,如果要使用 mingw make 文件,需要手动定义并传递给 cmake。 (在柯南文档here 中找到了这一点。但请注意,该页面上的柯南文件有些不完整。最后,您必须将默认柯南配置文件中的其他元素添加到您将用于构建的柯南配置文件中以针对MinGw 平台使用 mingw 工具链。

      toolchain=C:/msys64/mingw64/bin
      target_host=x86_64-w64-mingw32
      cc_compiler=gcc
      cxx_compiler=g++
      
      [env]
      CONAN_CMAKE_FIND_ROOT_PATH=$toolchain
      CHOST=$target_host
      AR=$target_host-ar
      AS=$target_host-as
      RANLIB=$target_host-ranlib
      CC=$target_host-$cc_compiler
      CXX=$target_host-$cxx_compiler
      STRIP=$target_host-strip
      RC=$target_host-windres
      
      
      [settings]
      #We are cross-building to Window
      [settings]
      os=Windows
      os_build=Windows
      arch=x86_64
      arch_build=x86_64
      compiler=gcc
      build_type=Release
      compiler.libcxx=libstdc++11
      compiler.cppstd=20
      compiler.version=10
      [options]
      [env]
      CC=C:/msys64/mingw64/bin/gcc
      CXX=C:/msys64/mingw64/bin/g++
      

      请注意,CC 和 CXX 工具链变量是重复的,但老实说,我不在乎。我想以尽可能多的方式告诉 windows 和 cmake 来使用它们。

    最后,可能最容易将此视为“交叉编译”,因为默认安装的 cmake、路径变量和 windows 平台未设置为使用非 windows 编译器进行编译。这个来自柯南的page(较新)描述了如何在 Windows 机器上定义它。顶部有一些背景知识,但有助于了解这些工具之间发生的情况。

    最后...毕竟,我要看看忍者,因为它似乎会提高我的生活质量。我还将切换到 conanfile.py 而不是 conanfile.txt,因为文档更适合这些。

    【讨论】:

      【解决方案2】:

      可以通过更新默认配置文件或为 MinGW 创建新配置文件来解决此问题。

      1. 更新默认配置文件:
      conan profile update settings.compiler=gcc /path/to/profile
      conan profile update settings.compiler.version=9.2 /path/to/profile
      conan profile update settings.compiler.libcxx=libstdc++11 /path/to/profile
      
      1. 在路径 .conan/profile/ 处创建新的 propfile
      [build_requires]
      mingw_installer/1.0@conan/stable
      msys2/20190524
      
      [settings]
      os_build=Windows
      os=Windows
      arch=x86_64
      arch_build=x86_64
      compiler=gcc
      compiler.version=4.9
      compiler.libcxx=libstdc++11
      compiler.threads=posix
      build_type=Release
      

      注意: 需要在 windows 环境下添加 MinGW/bin 路径。 开发者可以根据自己的安装选择编译器版本。

      【讨论】:

      • 要管理配置文件,有一个很好的实用程序:conan config install,它允许将配置文件(和其他东西,如自定义 settings.yml、remotes.txt、自定义 conan.conf)存储在git repo 或 http zip 文件,并使用此共享配置更新您的柯南客户端。 docs.conan.io/en/latest/reference/commands/consumer/…
      • 太好了。我会试试conan config
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多