gcc 候选函数不可行:没有已知的从“LPTSTR”(也称为“char *”)到“const OLECHAR *”(也称为“const wchar_t *”)的转换

fcipmucu  于 2023-01-17  发布在  其他
关注(0)|答案(1)|浏览(168)

我不希望解决方案更改源代码。请让Clang分析源代码而不进行修改。

    • 测试类. cpp**
#include <Windows.h>

class TestClass {
public:
    TestClass(LPTSTR test);
};

TestClass::TestClass(LPTSTR i_dumpPath) {
    BSTR bstr = SysAllocString(i_dumpPath);
}
    • 运行命令**
clang TestClass.cpp -m32 -w
    • 产出**
TestClass.cpp:9:17: error: no matching function for call to 'SysAllocString'
    BSTR bstr = SysAllocString(i_dumpPath);
                ^~~~~~~~~~~~~~
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\oleauto.h:64:21: note: candidate function not viable: no known conversion from 'LPTSTR' (aka 'char *') to 'const OLECHAR *' (aka 'const wchar_t *') for
      1st argument
WINOLEAUTAPI_(BSTR) SysAllocString(__in_z_opt const OLECHAR * psz);
                    ^
1 error generated.
    • 详细输出:**
clang version 12.0.0
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM-12\bin
 "C:\\Program Files\\LLVM-12\\bin\\clang.exe" -cc1 -triple x86_64-pc-windows-msvc19.16.27042 -emit-obj -mrelax-all -mincremental-linker-compatible --mrelax-relocations -disable-free -disable-llvm-verifier -discard-value-names -main-file-name TestClass.cpp -mrelocation-model pic -pic-level 2 -mframe-pointer=none -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -v -resource-dir "C:\\Program Files\\LLVM-12\\lib\\clang\\12.0.0" -internal-isystem "C:\\Program Files\\LLVM-12\\lib\\clang\\12.0.0\\include" -internal-isystem "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Professional\\VC\\Tools\\MSVC\\14.16.27023\\include" -internal-isystem "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Professional\\VC\\Tools\\MSVC\\14.16.27023\\atlmfc\\include" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.17763.0\\ucrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.17763.0\\shared" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.17763.0\\um" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.17763.0\\winrt" -fdeprecated-macro -fdebug-compilation-dir "C:\\Users\\Administrator\\Documents\\Veno\\CodeChecker" -ferror-limit 19 -fmessage-length=142 -fno-use-cxa-atexit -fms-extensions -fms-compatibility -fms-compatibility-version=19.16.27042 -std=c++14 -fdelayed-template-parsing -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -o "C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\TestClass-5ef61a.o" -x c++ TestClass.cpp
clang -cc1 version 12.0.0 based upon LLVM 12.0.0 default target x86_64-pc-windows-msvc
#include "..." search starts here:
#include <...> search starts here:
 C:\Program Files\LLVM-12\lib\clang\12.0.0\include
 C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\include
 C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\atlmfc\include
 C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt
 C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared
 C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um
 C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\winrt
End of search list.
TestClass.cpp:9:17: error: no matching function for call to 'SysAllocString'
    BSTR bstr = SysAllocString(i_dumpPath);
                ^~~~~~~~~~~~~~
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\oleauto.h:74:21: note: candidate function not viable: no known conversion from
      'LPTSTR' (aka 'char *') to 'const OLECHAR *' (aka 'const wchar_t *') for 1st argument
WINOLEAUTAPI_(BSTR) SysAllocString(_In_opt_z_ const OLECHAR * psz);
                    ^
1 error generated.

操作系统:Windows 10配置文件12.0.0目标:x86_64-pc-windows-msvc线程型号:波斯
尝试使用Clang编译器编译C++源代码。但它导致与没有匹配的函数调用相关的错误。

b4wnujal

b4wnujal1#

使用-DUNICODE将Macro添加到编译器参数解决了这个问题。

clang TestClass.cpp -m32 -w -DUNICODE

相关问题