xmake运行xtd报错
Xmake 版本
2.8.6
操作系统版本和架构
Windows 11 pro 23H2
描述问题
根据安装教程安装了xtd-0.1.1beta版本,安装路径为C:\Program Files (x86)\xtd,使用xmake运行报错,这样:xtd.forms.lib(cursors.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug' in hello_world.cpp.obj xtd.forms.lib(theme_colors.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in hello_world.cpp.obj
期待的结果
正确链接执行
工程配置
-------------------------xmake.lua------------------- add_rules("mode.debug","mode.release") set_languages("c++20")
set_runtimes("MD") add_requires("cmake::xtd", {alias = "xtd", configs = {envs = {CMAKE_PREFIX_PATH = "C:\Program Files (x86)\xtd"}, vc_runtime="MD"}})
target("hello_world") set_kind("binary") add_files("src/*.cpp") add_packages("xtd") if is_mode("debug") then add_defines("DEBUG") end --------------------------src/hello_world.cpp--------------------------------
#include <xtd/xtd>
using namespace xtd::forms;
class main_form : public form { public: main_form() { text("Hello world (message_box)");
button1.location({10, 10});
button1.parent(*this);
button1.text("&Click me");
button1.click += [] {
message_box::show("Hello, World!");
};
}
private: button button1; };
auto main()->int { application::run(main_form()); }
附加信息和错误日志
Bot detected the issue body's language is not English, translate it automatically.
Title: xmake reports an error when running xtd
明明用了 set_runtimes("MD"),但编译出来是 MDd?重新构建看看编译命令
xmake f -c
xmake -rv
嗯嗯,是的,设置了MD,编译出的是MDd,编译命令如下,完整输出在log2.txt。 log2.txt
(base) PS E:\cpp\xmakextd> xmake -rv checking for cl.exe ... D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\bin\HostX64\x64\cl.exe checking for the c++ compiler (cxx) ... cl.exe checking for D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\bin\HostX64\x64\cl.exe ... ok checking for flags (-O2 -fp:fast) ... ok checking for flags (-std:c++20) ... ok checking for flags (cl_external_includedir) ... ok checking for flags (-DNDEBUG) ... ok [ 25%]: compiling.release src\hello_world.cpp "D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\bin\HostX64\x64\cl.exe" -c -nologo -O2 -fp:fast -std:c++20 -MD -DWIN32 -D_WINDOWS -D_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS "-D__CMAKE_INSTALL_PREFIX__="C:/Program Files (x86)/find_package"" "-D__XTD_INCLUDE_PATH__="C:/Program Files (x86)/xtd/include"" "-D__XTD_LIB_PATH__="C:/Program Files (x86)/xtd/lib"" "-D__XTD_CONSOLE_INCLUDE_PATH__="C:/Program Files (x86)/xtd/include"" "-D__XTD_CONSOLE_LIB_PATH__="C:/Program Files (x86)/xtd/lib"" "-D__XTD_FORMS_INCLUDE_PATH__="C:/Program Files (x86)/xtd/include"" "-D__XTD_FORMS_LIB_PATH__="C:/Program Files (x86)/xtd/lib"" "-D__XTD_FORMS_RESOURCES_PATH__="C:/Program Files (x86)/xtd/share/xtd/resources"" -DCMAKE_INTDIR="Debug" -D_DEBUG "-D__CMAKE_INSTALL_PREFIX__=\"C:/Program Files (x86)/find_package\"" "-D__XTD_INCLUDE_PATH__=\"C:/Program Files (x86)/xtd/include\"" "-D__XTD_LIB_PATH__=\"C:/Program Files (x86)/xtd/lib\"" "-D__XTD_CONSOLE_INCLUDE_PATH__=\"C:/Program Files (x86)/xtd/include\"" "-D__XTD_CONSOLE_LIB_PATH__=\"C:/Program Files (x86)/xtd/lib\"" "-D__XTD_FORMS_INCLUDE_PATH__=\"C:/Program Files (x86)/xtd/include\"" "-D__XTD_FORMS_LIB_PATH__=\"C:/Program Files (x86)/xtd/lib\"" "-D__XTD_FORMS_RESOURCES_PATH__=\"C:/Program Files (x86)/xtd/share/xtd/resources\"" -DCMAKE_INTDIR=\"Debug\" -DCMAKE_INTDIR="Release" -DCMAKE_INTDIR=\"Release\" -DCMAKE_INTDIR="MinSizeRel" -DCMAKE_INTDIR=\"MinSizeRel\" -DCMAKE_INTDIR="RelWithDebInfo" -DCMAKE_INTDIR=\"RelWithDebInfo\" /EHsc -external:W0 "-external:IC:\Program Files (x86)\xtd\cmake\..\include" -external:W0 "-external:IC:\Program Files (x86)\xtd\include" -DNDEBUG -Fobuild.objs\hello_world\windows\x64\release\src\hello_world.cpp.obj src\hello_world.cpp checking for flags (cl_sourceDependencies) ... ok [ 50%]: linking.release hello_world.exe "D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\bin\HostX64\x64\link.exe" -nologo -dynamicbase -nxcompat -machine:x64 "-libpath:C:\Program Files (x86)\xtd\lib" "-libpath:C:\Program Files (x86)\wxWidgets\lib\vc_x64_lib" /opt:ref /opt:icf wxbase31ud.lib wxmsw31ud_core.lib wxmsw31ud_xrc.lib wxpngd.lib wxtiffd.lib wxjpegd.lib wxzlibd.lib wxregexud.lib wxexpatd.lib xtd.lib xtd.forms.lib xtd.forms.native.wxwidgets.lib xtd.drawing.lib xtd.drawing.native.wxwidgets.lib xtd.tunit.lib xtd.core.lib xtd.core.native.win32.lib xtd.3rdparty.call_stack.lib xtdd.lib xtd.formsd.lib xtd.forms.native.wxwidgetsd.lib xtd.drawingd.lib xtd.drawing.native.wxwidgetsd.lib wxbase31u.lib wxmsw31u_core.lib wxmsw31u_xrc.lib wxpng.lib wxtiff.lib wxjpeg.lib wxzlib.lib wxregexu.lib wxexpat.lib xtd.tunitd.lib xtd.cored.lib xtd.core.native.win32d.lib xtd.3rdparty.call_stackd.lib -out:build\windows\x64\release\hello_world.exe build.objs\hello_world\windows\x64\release\src\hello_world.cpp.obj error: xtd.forms.lib(cursors.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in hello_world.cpp.obj xtd.forms.lib(cursors.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug' in hello_world.cpp.obj
看起来你编译的xtd是debug版用的MDd,试试用-DCMAKE_BUILD_TYPE=Release 重新编译xtd
Bot detected the issue body's language is not English, translate it automatically.
It seems that the xtd you compiled is MDd for debug version. Try using -DCMAKE_BUILD_TYPE=Release to recompile xtd.
安装的既有release版本也有debug版本,使用CMakeList.txt来创建的hello_world,debug和release都是可以运行的 ---------------CMakeLists.txt---------------------- cmake_minimum_required(VERSION 3.3) set(XTD_DOWNLOAD_DOXYGEN OFF) project(hello_world_form) find_package(xtd REQUIRED) add_sources(src/hello_world_form.cpp) target_type(GUI_APPLICATION) ---------------src/hello_world_form.cpp-------------- #include <xtd/xtd>
using namespace xtd::forms;
class main_form : public form { public: main_form() { text("Hello world (message_box)");
button1.location({ 10, 10 });
button1.parent(*this);
button1.text("&Click me");
button1.click += [] {
message_box::show("Hello, World!");
};
}
private: button button1; };
auto main() -> int { application::run(main_form()); }
set_runtimes("MD") 目前仅仅只支持同步进 xmake-repo 等 xmake 自有包的配置。。cmake::xtd 属于直接借助 cmake 查找包,目前没有传递 vs runtime 进去。
主工程你用了 MD,cmake::xtd 里面还是走了默认的库查找,一种看下 cmake find_package 有哪些参数可以调 vs runtime 的,在 add_requires 里面设置进去。。
一种提 pr 到 xmake-repo ,入库 xtd ,直接走 xmake 包管理安装,这是推荐做法。。cmake::xxx 的包查找原本就比较 hack ,可靠性不高,要各种传参配置。
xtd库依赖wxwidgets,xtd脚本安装的时候会把wxwidgets安装到C:\Program Files (x86)\wxWidgets路径然后引用,下面写的xtd/xmake.lua该怎么修改呢? -----------x/xtd/xmake.lua----------------------
package("xtd")
set_homepage("https://gammasoft71.github.io/xtd")
set_description("Free open-source modern C++17 / C++20 framework to create console, GUI (forms like WinForms) and unit test applications on Microsoft Windows, Apple macOS and Linux.")
set_license("MIT")
add_urls("https://media.githubusercontent.com/media/stevexuzeta/xtd-tag/main/xtd-$(version).tar.gz?download=true")
add_versions("v0.1.1-beta","dd6f33e32aa4923051fd3df037a2ceefdc63bb756748f246e60129f72b98338d")
add_deps("cmake")
on_install("windows", function (package)
local configs = {}
table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
import("package.tools.cmake").install(package, configs)
end)
on_test(function (package)
assert(package:check_cxxsnippets({test = [[
#include <xtd/xtd>
using namespace xtd;
void test() {
console::background_color(console_color::blue);
console::foreground_color(console_color::white);
console::write_line("Hello, World!");
}
]]}, {configs = {languages = "c++20"}, tryrun = true, output = true}))
end)
打 patch ,禁用它内部的 wxwidget 安装,然后让它使用 add_deps("wxwidgets") 依赖
Bot detected the issue body's language is not English, translate it automatically.
patch it to disable its internal wxwidget installation and then make it use the add_deps("wxwidgets") dependency