如何通过Conan让Meson找到指定名称的windres二进制文件?
问题描述
在Linux主机上使用mingw32进行交叉编译,通过Conan包管理器构建freetype 2.13.2及其他依赖时,出现以下错误:
../src/meson.build:239:11: ERROR: Could not find Windows resource compiler
已知Meson默认查找名为windres的二进制文件,但我的资源编译器实际名为x86_64-w64-mingw32-windres。
如何通过Conan告知Meson我的windres二进制文件的名称?
相关配置信息
- 执行的Conan命令:
conan install .. -pr:b=default -pr:h=windows-cross --build=missing
~/.conan/profiles/default内容:
[settings] os=Linux os_build=Linux arch=x86_64 arch_build=x86_64 compiler=gcc compiler.version=11 compiler.libcxx=libstdc++11 build_type=Release [options] [build_requires] [env]
~/.conan/profiles/windows-cross内容:
[settings] os=Windows os_build=Linux arch=x86_64 arch_build=x86_64 compiler=gcc compiler.version=10 compiler.libcxx=libstdc++11 build_type=Release [env] CONAN_CMAKE_TOOLCHAIN_FILE=/home/per/mingw-w64-x86_64.cmake CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ AR=x86_64-w64-mingw32-ar AS=x86_64-w64-mingw32-as RANLIB=x86_64-w64-mingw32-ranlib STRIP=x86_64-w64-mingw32-strip RC=x86_64-w64-mingw32-windres CONAN_CMAKE_GENERATOR=MinGW Makefiles
/home/per/mingw-w64-x86_64.cmake内容:
set(CMAKE_SYSTEM_NAME Windows) set(TOOLCHAIN_PREFIX x86_64-w64-mingw32) # cross compilers to use for C, C++ and Fortran set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc) set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++) set(CMAKE_Fortran_COMPILER ${TOOLCHAIN_PREFIX}-gfortran) set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres) # target environment on the build host system set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX}) # modify default behavior of FIND_XXX() commands set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
解决方案
针对Meson找不到交叉编译版本的windres问题,可通过以下几种Conan相关方式解决:
1. 在Conan profile中添加Meson专属环境变量
Meson支持通过MESON_RC环境变量指定资源编译器路径,直接在windows-cross profile的[env]段添加:
MESON_RC=x86_64-w64-mingw32-windres
Conan运行Meson构建时会自动传递该变量,让Meson使用指定的windres二进制文件。
2. 通过Conan传递Meson配置参数
如果需要更灵活的配置,可在profile中设置MESON_ARGS环境变量,直接指定资源编译器:
MESON_ARGS=-Drc=x86_64-w64-mingw32-windres
或者通过Meson交叉配置文件传递:
MESON_ARGS=--cross-file=/path/to/your/meson-cross-config.txt
其中meson-cross-config.txt需包含:
[binaries] rc = 'x86_64-w64-mingw32-windres'
3. 确保RC环境变量被构建进程读取
虽然你已在profile中设置RC=x86_64-w64-mingw32-windres,但部分Meson版本可能不会自动读取该变量。可在profile中添加导出声明,确保变量传递到构建子进程:
[env] # 保留原有环境变量... RC=x86_64-w64-mingw32-windres export RC
4. 补充:创建软链接(简单有效)
如果上述Conan相关方法不生效,可在系统PATH目录下创建软链接,让Meson找到默认名称的二进制文件:
sudo ln -s /usr/bin/x86_64-w64-mingw32-windres /usr/bin/windres
内容的提问来源于stack exchange,提问作者Pibben
相关产品推荐
相关产品推荐

