stack traceback:
[C]: in function 'error'
[@programdir\core\base\os.lua:973]:
[@programdir\modules\core\tools\link.lua:175]: in function 'catch'
[@programdir\core\sandbox\modules\try.lua:123]: in function 'try'
[@programdir\modules\core\tools\link.lua:150]:
[C]: in function 'xpcall'
[@programdir\core\base\utils.lua:275]:
[@programdir\core\tool\linker.lua:221]: in function 'link'
[@programdir\actions\build\kinds\shared.lua:53]: in function 'callback'
[@programdir\modules\core\project\depend.lua:217]: in function 'on_changed'
[@programdir\actions\build\kinds\shared.lua:41]: in function '_do_link_target'
[@programdir\actions\build\kinds\shared.lua:84]:
[@programdir\actions\build\kinds\shared.lua:111]: in function '_link_target'
[@programdir\actions\build\kinds\shared.lua:139]: in function 'jobfunc'
[@programdir\modules\async\runjobs.lua:241]:
[C]: in function 'xpcall'
[@programdir\core\base\utils.lua:275]: in function 'trycall'
[@programdir\core\sandbox\modules\try.lua:117]: in function 'try'
[@programdir\modules\async\runjobs.lua:223]: in function 'cotask'
[@programdir\core\base\scheduler.lua:406]:
stack traceback:
[C]: in function 'error'
@programdir\core\base\os.lua:973: in function 'os.raiselevel'
(...tail calls...)
@programdir\core\main.lua:329: in upvalue 'cotask'
@programdir\core\base\scheduler.lua:406: in function <@programdir\core\base\scheduler.lua:399>
Xmake 版本
v2.9.3
操作系统版本和架构
Windows 22H2
描述问题
在使用 MSVC modules 构建动态库时, 会报链接错误. 如下代码设置
set_kind("binary")
便可编译通过; 但编译到.dll
时会报错:在 microsoft/STL#4343 中提到这个错误是由于未链接
std.obj
导致的, 查看-vD
后可以发现,set_kind("binary")
链接了std.obj
而set_kind("shared")
确实未链接期待的结果
编译通过
工程配置
xmake.lua
main.cpp
附加信息和错误日志
[ 0%]: generating.module.deps src\main.cpp
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\bin\HostX64\x64\cl.exe -nologo -std:c++latest /EHsc -TP -scanDependencies build.gens\module\windows\x64\release\rules\bmi\cache\modules\79494dc4\main.cpp.module.json src\main.cpp -ifcOutput build.gens\module\windows\x64\release\rules\bmi\cache\modules\79494dc4 -Fobuild.objs\module\windows\x64\release\src\main.cpp.obj
[ 0%]: generating.module.deps C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\modules\std.ixx
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\bin\HostX64\x64\cl.exe -nologo -std:c++latest /EHsc -TP -scanDependencies build.gens\module\windows\x64\release\rules\bmi\cache\modules\e1085abc\std.ixx.module.json "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\modules\std.ixx" -ifcOutput build.gens\module\windows\x64\release\rules\bmi\cache\modules\e1085abc -Fobuild.objs\module\windows\x64\release\889e61fa4b2b4a678264d65ff7ac448b\std.ixx.obj
[ 0%]: generating.module.deps C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\modules\std.compat.ixx
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\bin\HostX64\x64\cl.exe -nologo -std:c++latest /EHsc -TP -scanDependencies build.gens\module\windows\x64\release\rules\bmi\cache\modules\e1085abc\std.compat.ixx.module.json "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\modules\std.compat.ixx" -ifcOutput build.gens\module\windows\x64\release\rules\bmi\cache\modules\e1085abc -Fobuild.objs\module\windows\x64\release\889e61fa4b2b4a678264d65ff7ac448b\std.compat.ixx.obj
main.cpp
std.ixx
std.compat.ixx
[ 37%]: compiling.bmi.release std
"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\bin\HostX64\x64\cl.exe" -c -nologo -std:c++latest /EHsc -TP -ifcOutput build.gens\module\windows\x64\release\rules\bmi\cache\modules\e1085abc\std.ifc -interface -ifcOnly -Fobuild.gens\module\windows\x64\release\rules\bmi\cache\modules\e1085abc\std.ifc "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\modules\std.ixx"
[ 50%]: compiling.bmi.release std.compat
"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\bin\HostX64\x64\cl.exe" -c -nologo -std:c++latest /EHsc -reference std=build.gens\module\windows\x64\release\rules\bmi\cache\modules\e1085abc\std.ifc -TP -ifcOutput build.gens\module\windows\x64\release\rules\bmi\cache\modules\e1085abc\std.compat.ifc -interface -ifcOnly -Fobuild.gens\module\windows\x64\release\rules\bmi\cache\modules\e1085abc\std.compat.ifc "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\modules\std.compat.ixx"
[ 75%]: compiling.release src\main.cpp
"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\bin\HostX64\x64\cl.exe" -c -nologo -std:c++latest /EHsc -reference std=build.gens\module\windows\x64\release\rules\bmi\cache\modules\e1085abc\std.ifc -Fobuild.objs\module\windows\x64\release\src\main.cpp.obj src\main.cpp
[ 87%]: linking.release module.dll
"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\bin\HostX64\x64\link.exe" -dll -nologo -machine:x64 -out:build\windows\x64\release\module.dll build.objs\module\windows\x64\release\src\main.cpp.obj
error: @programdir\core\main.lua:329: @programdir\actions\build\main.lua:148: @programdir\modules\async\runjobs.lua:325: @programdir\actions\build\kinds\shared.lua:53: @programdir\modules\core\tools\link.lua:175: main.cpp.obj : error LNK2019: 无法解析的外部符号 "public: static int const std::_General_precision_tables_2::_Max_P" (?_Max_P@?$_General_precision_tables_2@N@std@@2HB),函数 "struct std::to_chars_result cdecl std::_Floating_to_chars_general_precision(char ,char const,double,int)" (??$_Floating_to_chars_general_precision@N@std@@YA?AUto_chars_result@0@PEADQEADNH@Z) 中引用了该符号
main.cpp.obj : error LNK2019: 无法解析的外部符号 "public: static int const std::_General_precision_tables_2::_Max_P" (?_Max_P@?$_General_precision_tables_2@M@std@@2HB),函数 "struct std::to_chars_result cdecl std::_Floating_to_chars_general_precision(char ,char const,float,int)" (??$_Floating_to_chars_general_precision@M@std@@YA?AUto_chars_result@0@PEADQEADMH@Z) 中引用了该符号
build\windows\x64\release\module.dll : fatal error LNK1120: 2 个无法解析的外部命令
stack traceback: [C]: in function 'error' [@programdir\core\base\os.lua:973]: [@programdir\modules\core\tools\link.lua:175]: in function 'catch' [@programdir\core\sandbox\modules\try.lua:123]: in function 'try' [@programdir\modules\core\tools\link.lua:150]: [C]: in function 'xpcall' [@programdir\core\base\utils.lua:275]: [@programdir\core\tool\linker.lua:221]: in function 'link' [@programdir\actions\build\kinds\shared.lua:53]: in function 'callback' [@programdir\modules\core\project\depend.lua:217]: in function 'on_changed' [@programdir\actions\build\kinds\shared.lua:41]: in function '_do_link_target' [@programdir\actions\build\kinds\shared.lua:84]: [@programdir\actions\build\kinds\shared.lua:111]: in function '_link_target' [@programdir\actions\build\kinds\shared.lua:139]: in function 'jobfunc' [@programdir\modules\async\runjobs.lua:241]: [C]: in function 'xpcall' [@programdir\core\base\utils.lua:275]: in function 'trycall' [@programdir\core\sandbox\modules\try.lua:117]: in function 'try' [@programdir\modules\async\runjobs.lua:223]: in function 'cotask' [@programdir\core\base\scheduler.lua:406]:
stack traceback: [C]: in function 'error' @programdir\core\base\os.lua:973: in function 'os.raiselevel' (...tail calls...) @programdir\core\main.lua:329: in upvalue 'cotask' @programdir\core\base\scheduler.lua:406: in function <@programdir\core\base\scheduler.lua:399>