You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows下VSCode用CMake+MinGW编译fmt程序报/utf-8找不到错误

MinGW下CMake编译含fmt库的C++程序报错:/utf-8 链接器输入文件未找到

开发环境

  • 系统:Windows
  • IDE:VSCode
  • 工具链:gcc 13.1.0 x86_64-w64-mingw32

问题场景

使用CMake构建以下C++程序时触发错误,切换Visual Studio工具链编译正常:

#include "fmt/format.h"

int main(int, char **)
{
    fmt::print("Hello,world!\n");
}

错误信息

编译时报错:g++.exe: error: /utf-8: linker input file not found: No such file or directory
完整编译日志:

[main] 正在生成文件夹: c:/Users/syk/Desktop/c-c++/build 
[build] 正在启动生成
[proc] 执行命令: chcp
[proc] 执行命令: D:\mingw64\bin\cmake.EXE --build c:/Users/syk/Desktop/c-c++/build --config Debug --target all -j 10 --
[build] D:\mingw64\bin\cmake.exe -SC:\Users\syk\Desktop\c-c++ -BC:\Users\syk\Desktop\c-c++\build --check-build-system CMakeFiles\Makefile.cmake 0
[build] D:\mingw64\bin\cmake.exe -E cmake_progress_start C:\Users\syk\Desktop\c-c++\build\CMakeFiles C:\Users\syk\Desktop\c-c++\build\\CMakeFiles\progress.marks
[build] D:/mingw64/bin/mingw32-make.exe  -f CMakeFiles\Makefile2 all
[build] mingw32-make[1]: Entering directory 'C:/Users/syk/Desktop/c-c++/build'
[build] D:/mingw64/bin/mingw32-make.exe  -f CMakeFiles\TestVcpkg.dir\build.make CMakeFiles/TestVcpkg.dir/depend
[build] mingw32-make[2]: Entering directory 'C:/Users/syk/Desktop/c-c++/build'
[build] D:\mingw64\bin\cmake.exe -E cmake_depends "MinGW Makefiles" C:\Users\syk\Desktop\c-c++ C:\Users\syk\Desktop\c-c++ C:\Users\syk\Desktop\c-c++\build C:\Users\syk\Desktop\c-c++\build C:\Users\syk\Desktop\c-c++\build\CMakeFiles\TestVcpkg.dir\DependInfo.cmake --color=
[build] mingw32-make[2]: Leaving directory 'C:/Users/syk/Desktop/c-c++/build'
[build] D:/mingw64/bin/mingw32-make.exe  -f CMakeFiles\TestVcpkg.dir\build.make CMakeFiles/TestVcpkg.dir/build
[build] mingw32-make[2]: Entering directory 'C:/Users/syk/Desktop/c-c++/build'
[build] [ 50%] Building CXX object CMakeFiles/TestVcpkg.dir/a.cpp.obj
[build] D:\mingw64\bin\g++.exe -DFMT_SHARED @CMakeFiles/TestVcpkg.dir/includes_CXX.rsp -g /utf-8 -MD -MT CMakeFiles/TestVcpkg.dir/a.cpp.obj -MF CMakeFiles\TestVcpkg.dir\a.cpp.obj.d -o CMakeFiles/TestVcpkg.dir/a.cpp.obj -c C:\Users\syk\Desktop\c-c++\a.cpp
[build] g++.exe: warning: /utf-8: linker input file unused because linking not done
[build] g++.exe: error: /utf-8: linker input file not found: No such file or directory
[build] mingw32-make[2]: *** [CMakeFiles\TestVcpkg.dir\build.make:79: CMakeFiles/TestVcpkg.dir/a.cpp.obj] Error 1
[build] mingw32-make[2]: *** Deleting file 'CMakeFiles/TestVcpkg.dir/a.cpp.obj'
[build] mingw32-make[2]: Leaving directory 'C:/Users/syk/Desktop/c-c++/build'
[build] mingw32-make[1]: *** [CMakeFiles\Makefile2:85: CMakeFiles/TestVcpkg.dir/all] Error 2
[build] mingw32-make[1]: Leaving directory 'C:/Users/syk/Desktop/c-c++/build'
[build] mingw32-make: *** [Makefile:93: all] Error 2
[proc] 命令“D:\mingw64\bin\cmake.EXE --build c:/Users/syk/Desktop/c-c++/build --config Debug --target all -j 10 --”已退出,代码为 2
[driver] 生成完毕: 00:00:01.612
[build] 生成已完成,退出代码为 2

CMakeLists.txt内容

cmake_minimum_required(VERSION 3.0)
add_executable(TestVcpkg a.cpp)
set(CMAKE_VERBOSE_MAKEFILE ON)
find_package(fmt CONFIG REQUIRED)
target_link_libraries(TestVcpkg PRIVATE fmt::fmt)

补充说明

已设置CMD和PowerShell为UTF-8,谷歌、StackOverflow搜索未找到解决方案。


内容的提问来源于stack exchange,提问作者MytechDream

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 18:23:11