Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

正常的静态库,也无法使用 #604

Closed
Ultraman95 opened this issue Oct 24, 2019 · 8 comments
Closed

正常的静态库,也无法使用 #604

Ultraman95 opened this issue Oct 24, 2019 · 8 comments

Comments

@Ultraman95
Copy link

xmake.lua

-- add modes: debug and release
add_rules("mode.debug", "mode.release")

add_defines("_WIN32_WINNT=0x600")

-- add target
target("test")

-- set kind
set_kind("binary")

-- add files
add_includedirs("src/")
add_includedirs("generated/")
add_includedirs("C:/Tools/vcpkg/installed/x64-windows/include/")
    add_files("src/*.cpp")
add_files("generated/*.cc")


add_linkdirs("C:/Tools/vcpkg/installed/x64-windows/lib/")
add_links("grpc++_unsecure")
add_links("libprotobuf")
add_links("ws2_32")

grpc++_unsecure.lib这个库是个静态库

-----错误信息-----------
error LNK2038: 检测到“RuntimeLibrary”的不匹配项: 值“MD_DynamicRelease”不匹配值“MT_StaticRelease”(hello_server_impl.cpp.obj
中)

@Ultraman95
Copy link
Author

自己编译的release版的静态库,到底怎么样才能被识别呢?

@waruqi
Copy link
Member

waruqi commented Oct 24, 2019

mt md不匹配哈,test是mt的 库是md的 当然有这问题了 跟xmake没啥关系。。你自己add_ldflags 设置下runtime flags -MT -MD,保证两边一致就行了

@Ultraman95
Copy link
Author

add_ldflags("-MT")

@Ultraman95
Copy link
Author

这样也不行啊

@Ultraman95
Copy link
Author

add_ldflags这个怎么用啊

@Ultraman95
Copy link
Author

好像是库是mt的, test是md的

@waruqi
Copy link
Member

waruqi commented Oct 24, 2019

这样也不行啊

看你的错误提示哈

“MT_StaticRelease”(hello_server_impl.cpp.obj中)

这不明显你的test是MT么,你还去通过add_ldflags设置 MT ,当然没效果了。

@waruqi
Copy link
Member

waruqi commented Oct 24, 2019

add_linkdirs("C:/Tools/vcpkg/installed/x64-windows/lib/")

看你加的库搜索目录,x64-windows,这个里面的vcpkg lib都是 MD 版本的,只有 x64-windows-static目录下的才是 MT版本的。。

而你的test明显是MT的(根据错误提示),所以肯定会冲突。。

一种方式,全部走MD,也就是test下xmake.lua里面设置到MD, add_ldflags("-MD")
另外一种方式,全部走MT,也就是add_linkdirs 指定到 x64-windows-static的 vcpkg lib目录,选择MT版本的vcpkg库。。

其实这块跟xmake没啥关系,建议你先查看下vcpkg下关于MT/MD的切换支持文档和相关资料:
https://blogs.msdn.microsoft.com/c/2016/12/14/vcpkg%e6%9b%b4%e6%96%b0%ef%bc%9a%e9%9d%99%e6%80%81%e9%93%be%e6%8e%a5/
microsoft/vcpkg#36

或者直接走add_requires("vcpkg::xxx"),我刚dev版本已经支持vs_runtime的设置切换了。

而关于xmake里面add_ldflags的使用,见xmake的文档:https://xmake.io/#/manual/project_target?id=targetadd_ldflags

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants