DCMTK 字符集 Unicode 错误

DCMTK Character Set Unicode error

本文关键字:错误 Unicode 字符集 DCMTK      更新时间:2023-10-16

我正在使用Visual Studio 2013下的DCMTK库。在项目的属性中,如果我设置

Character Set: Use Unicode Character Set

编译时出现错误

Error   1   error C2678: binary '+' : no operator found which takes a left-hand operand of type 'const wchar_t [8]' (or there is no acceptable conversion)   C:DCMTKincludedcmtkoflogtracelog.h
Error   2   error C2664: 'void dcmtk::log4cplus::Logger::forcedLog(const dcmtk::log4cplus::spi::InternalLoggingEvent &) const' : cannot convert argument 3 from 'int' to 'const char *'   C:DCMTKincludedcmtkoflogtracelog.h 
Error   3   error C2678: binary '+' : no operator found which takes a left-hand operand of type 'const wchar_t [8]' (or there is no acceptable conversion)   C:DCMTKincludedcmtkoflogtracelog.h
Error   4   error C2664: 'void dcmtk::log4cplus::Logger::forcedLog(const dcmtk::log4cplus::spi::InternalLoggingEvent &) const' : cannot convert argument 3 from 'int' to 'const char *'   C:DCMTKincludedcmtkoflogtracelog.h
Error   5   error C2665: 'dcmtk::log4cplus::Logger::getInstance' : none of the 2 overloads could convert all the argument types   C:DCMTKincludedcmtkofloglogmacro.h
IntelliSense: no instance of overloaded function "dcmtk::log4cplus::Logger::getInstance" matches the argument list
            argument types are: (const dcmtk::log4cplus::tchar *)   c:DCMTKincludedcmtkofloglogmacro.h
IntelliSense: no operator "+" matches these operands
            operand types are: const wchar_t [8] + dcmtk::log4cplus::tstring   c:DCMTKincludedcmtkoflogtracelog.h
IntelliSense: no operator "+" matches these operands
            operand types are: const wchar_t [8] + dcmtk::log4cplus::tstring   c:DCMTKincludedcmtkoflogtracelog.h
IntelliSense: identifier "cerr" is undefined   c:UsersKyleGoogle Drivecpp_codesdicomDicomTesttest1Source.cpp
IntelliSense: identifier "endl" is undefined   c:UsersKyleGoogle Drivecpp_codesdicomDicomTesttest1Source.cpp

如果我设置Character Set: Use Multi-Byte Character Set我可以解决

但是我需要在另一个项目中使用 DCMTK,其中字符集必须是 Unicode。查看错误,问题仅在某个关于日志记录的类中,可能我永远不会使用:所以我尝试注释出现错误的代码行,现在我可以使用 Unicode 进行编译。

这是解决问题的独特方法吗?评论该部分时我会遇到什么问题?

根据 DCMTK 的 INSTALL 文件:

"定义 UNICODE 或 _UNICODE 时,DCMTK 不会编译,因为 然后,VisualStudio编译器使用Unicode版本而不是ANSI 所有 Windows API 函数的版本(即键入 wchar_t 而不是字符 对于所有字符串参数和返回值)。

也许,您应该使用具有动态链接的 DCMTK(作为 DLL)。但是,这需要使用当前的开发快照,而不是最新版本(即 3.6.0)。

我遇到了同样的问题。这个线程已经有几天的历史了,但也许有人可以使用这些信息。我发现一些线程存在类似的问题,但没有令人满意的解决方案。

我们遇到了一个问题,我们想将IDE从VS2008更改为VS2015。我们软件解决方案的所有(子)项目都是用UNICODE标志构建的。我们之前已经成功地将DCMTK 3.6.1集成到UNICODE项目中。

我下载了最新的DCMTK 3.6.1版本(3.6.1_20161102),并使用VS2015进行了编译。然后我尝试将静态库链接并编译到我们的软件解决方案,但这失败了(出现如上所述的相同错误)。

在尝试静态库、不同的 CMake 设置和共享库建议(也有一个完整的共享 DCMTK 库)数小时不成功后,我尝试了另一种方法。因为使用VS2008 IDE和UNICODE它已经可以工作了。

最后我成功了,因为我使用了较旧的 DCMTK 3.6.1 版本 (3.6.1_20120222)。

DCMTK 3.6.1 (20120222)

此版本不包含以下文件:

dcmtk\oflog\tracelog.h

目标项目设置 UNICODE 标志时,此文件会导致(在我的情况下)编译器和链接器错误。

此外,当标志DCMTK_OVERWRITE_WIN32_COMPILER_FLAGS被激活时,我收到了如下错误:

1>dcmnet.lib(assoc.obj):错误LNK2038:检测到"运行时库"不匹配:值"MTd_StaticDebug"与 DCMBase.obj 中的值"MDd_DynamicDebug"不匹配

没有标志,我能够毫无问题地使用编译的静态库。

希望这对某人有所帮助并保护很多时间。

问候