Skip to content

MinGW平台上cmake包编译问题 #5518

Closed
@24bit-xjkp

Description

@24bit-xjkp

Xmake 版本

xmake v2.9.4+HEAD.e85b001f1

操作系统版本和架构

Windows 11 24H2

描述问题

  1. 要使用gcc工具链编译Windows上的包需要使用mingw平台(一些包不支持cross平台),但gcc工具链可以独立安装,此时系统中不存在mingw相关环境,包括mingw32-make.exe。而xmake在mingw平台上默认需要该工具。
  2. xmake内建的clang和gcc工具链的c++工具链定义中,clang和gcc的定义先于clang++和g++,这会导致在mingw平台上使用上述工具链时,在链接阶段错误的使用clang和gcc去链接c++文件,导致缺少c++标准库进而链接失败。

期待的结果

  1. 在找不到mingw时自动尝试使用ninja
  2. 调整c++编译器的定义顺序

工程配置

add_requires("benchmark")
add_packages("benchmark")

target("test")
    add_files("*.cpp")

附加信息和错误日志

  1. 找不到mingw
xmake f --toolchain=clang -p mingw -c
checking for architecture ... x86_64
checking for Microsoft Visual Studio (x64) version ... 2022
checking for Microsoft C/C++ Compiler (x64) version ... 19.41.34120
note: install or modify (m) these packages (pass -y to skip confirm)?
in xmake-repo:
  -> benchmark 1.8.5 [toolchains:"clang"]
please input: y (y/n/m)
y
  => install benchmark 1.8.5 .. failed

mingw not found!
if you want to get more verbose errors, please see:
  -> C:\Users\2283\AppData\Local\.xmake\cache\packages\2408\b\benchmark\1.8.5\installdir.failed\logs\install.txt
error: install failed!
  1. 链接器错误

注意到链接时使用的是D:\\Tools\\clang\\bin\\clang.exe而不是clang++

kind: "try_compile-v1"
    backtrace:
      - "cmake/CXXFeatureCheck.cmake:41 (try_compile)"
      - "CMakeLists.txt:308 (cxx_feature_check)"
    directories:
      source: "C:/Users/2283/AppData/Local/.xmake/cache/packages/2408/b/benchmark/1.8.5/source/build_9ec7839e/CMakeFiles/CMakeTmp"
      binary: "C:/Users/2283/AppData/Local/.xmake/cache/packages/2408/b/benchmark/1.8.5/source/build_9ec7839e/CMakeFiles/CMakeTmp"
    cmakeVariables:
      CMAKE_CXX_COMPILER_CLANG_SCAN_DEPS: "D:/Tools/clang/bin/clang-scan-deps.exe"
      CMAKE_CXX_FLAGS: "-m64  -Wall  -Wextra  -Wshadow  -Wfloat-equal  -Wold-style-cast  -Wconversion  -Werror  -Wsuggest-override  -pedantic  -pedantic-errors  -Wshorten-64-to-32  -fstrict-aliasing  -Wno-deprecated-declarations  -Wno-deprecated  -Wstrict-aliasing  -Wthread-safety"
      CMAKE_CXX_FLAGS_DEBUG: "-g"
      CMAKE_EXE_LINKER_FLAGS: "-m64"
      CMAKE_MODULE_PATH: "C:/Users/2283/AppData/Local/.xmake/cache/packages/2408/b/benchmark/1.8.5/source/cmake/Modules;C:/Users/2283/AppData/Local/.xmake/cache/packages/2408/b/benchmark/1.8.5/source/cmake"
      CMAKE_OSX_SYSROOT: ""
    buildResult:
      variable: "COMPILE_HAVE_STD_REGEX"
      cached: true
      stdout: |
        Change Dir: 'C:/Users/2283/AppData/Local/.xmake/cache/packages/2408/b/benchmark/1.8.5/source/build_9ec7839e/CMakeFiles/CMakeTmp'
        
        Run Build Command(s): D:/Tools/CMake/bin/cmake.exe -E env VERBOSE=1 D:/Tools/build/bin/mingw32-make.exe -f Makefile cmTC_f92d4/fast
        D:/Tools/build/bin/mingw32-make.exe  -f CMakeFiles\\cmTC_f92d4.dir\\build.make CMakeFiles/cmTC_f92d4.dir/build
        mingw32-make[1]: Entering directory 'C:/Users/2283/AppData/Local/.xmake/cache/packages/2408/b/benchmark/1.8.5/source/build_9ec7839e/CMakeFiles/CMakeTmp'
        Building CXX object CMakeFiles/cmTC_f92d4.dir/std_regex.cpp.obj
        D:\\Tools\\clang\\bin\\clang.exe   -m64  -Wall  -Wextra  -Wshadow  -Wfloat-equal  -Wold-style-cast  -Wconversion  -Werror  -Wsuggest-override  -pedantic  -pedantic-errors  -Wshorten-64-to-32  -fstrict-aliasing  -Wno-deprecated-declarations  -Wno-deprecated  -Wstrict-aliasing  -Wthread-safety  -std=c++11 -MD -MT CMakeFiles/cmTC_f92d4.dir/std_regex.cpp.obj -MF CMakeFiles\\cmTC_f92d4.dir\\std_regex.cpp.obj.d -o CMakeFiles\\cmTC_f92d4.dir\\std_regex.cpp.obj -c C:\\Users\\2283\\AppData\\Local\\.xmake\\cache\\packages\\2408\\b\\benchmark\\1.8.5\\source\\cmake\\std_regex.cpp
        Linking CXX executable cmTC_f92d4.exe
        D:\\Tools\\CMake\\bin\\cmake.exe -E cmake_link_script CMakeFiles\\cmTC_f92d4.dir\\link.txt --verbose=1
        D:\\Tools\\CMake\\bin\\cmake.exe -E rm -f CMakeFiles\\cmTC_f92d4.dir/objects.a
        ar.exe qc CMakeFiles\\cmTC_f92d4.dir/objects.a @CMakeFiles\\cmTC_f92d4.dir\\objects1.rsp
        D:\\Tools\\clang\\bin\\clang.exe -m64  -Wall  -Wextra  -Wshadow  -Wfloat-equal  -Wold-style-cast  -Wconversion  -Werror  -Wsuggest-override  -pedantic  -pedantic-errors  -Wshorten-64-to-32  -fstrict-aliasing  -Wno-deprecated-declarations  -Wno-deprecated  -Wstrict-aliasing  -Wthread-safety  -m64  -Wl,--whole-archive CMakeFiles\\cmTC_f92d4.dir/objects.a -Wl,--no-whole-archive -o cmTC_f92d4.exe -Wl,--out-implib,libcmTC_f92d4.dll.a -Wl,--major-image-version,0,--minor-image-version,0 @CMakeFiles\\cmTC_f92d4.dir\\linkLibs.rsp
        ld.lld: error: undefined symbol: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::basic_string(char const*, std::allocator<char> const&)
        >>> referenced by objects.a(std_regex.cpp.obj):(main)
        ......
        ld.lld: error: undefined symbol: std::runtime_error::runtime_error(char const*)
        >>> referenced by objects.a(std_regex.cpp.obj):(std::regex_error::regex_error(std::regex_constants::error_type, char const*))
        
        ld.lld: error: too many errors emitted, stopping now (use --error-limit=0 to see all errors)
        clang: error: linker command failed with exit code 1 (use -v to see invocation)
        mingw32-make[1]: *** [CMakeFiles\\cmTC_f92d4.dir\\build.make:101: cmTC_f92d4.exe] Error 1
        mingw32-make[1]: Leaving directory 'C:/Users/2283/AppData/Local/.xmake/cache/packages/2408/b/benchmark/1.8.5/source/build_9ec7839e/CMakeFiles/CMakeTmp'
        mingw32-make: *** [Makefile:126: cmTC_f92d4/fast] Error 2
        
      exitCode: 2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions