VS字符集设置影响编译成功与否

王桑的一天 王桑的一天 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我使用开源库 muParser,是用来解析算式的
示例代码 :

#include <iostream>
#include "muParser.h"


int main(int argc, char* argv[])
{

double var_a = 1;
mu::Parser p;
p.SetExpr("3*8+9-1/8");
std::cout << p.Eval() << std::endl;
return 0;
}

使用 VS2019 ,必须将项目字符集设置成 “使用多字节字符集”,才能编译成功。

如果使用默认 “Unicode"字符集,IDE 会检测出类型错误:

E0415 不存在从 "const char [10]" 转换到 "std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t>>" 的适当构造函数 ConsoleApplication1
C2664 “void mu::ParserBase::SetExpr(const mu::string_type &)”: 无法将参数 1 从“const char [10]”转换为“const mu::string_type &” ConsoleApplication1



我将 "" 号字符串替换成 _T("") ,IDE 类型错误消失,但编译时报错:

错误 LNK2019 无法解析的外部符号 "__declspec(dllimport) public: void __cdecl mu::ParserBase::SetExpr(class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> > const &)" (__imp_?SetExpr@ParserBase@mu@@QEAAXAEBV?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@@Z),函数 main 中引用了该符号 ConsoleApplication1

好像是无法连接动态库

请问,如果我一定要用 Unicode 字符集,这个问题能解决吗?
...全文
评论 9
收藏 已收藏
分享
返回顶部
王桑的一天
C++ 语言 65,212 成员 250,513 内容