DCMTK 字符集 Unicode 错误

4
我将使用DCMTK库在Visual Studio 2013下进行编程。 如果我在项目属性中设置

,那么编译器会报错。
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:\DCMTK\include\dcmtk\oflog\tracelog.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:\DCMTK\include\dcmtk\oflog\tracelog.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:\DCMTK\include\dcmtk\oflog\tracelog.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:\DCMTK\include\dcmtk\oflog\tracelog.h
Error   5   error C2665: 'dcmtk::log4cplus::Logger::getInstance' : none of the 2 overloads could convert all the argument types   C:\DCMTK\include\dcmtk\oflog\logmacro.h
IntelliSense: no instance of overloaded function "dcmtk::log4cplus::Logger::getInstance" matches the argument list
            argument types are: (const dcmtk::log4cplus::tchar *)   c:\DCMTK\include\dcmtk\oflog\logmacro.h
IntelliSense: no operator "+" matches these operands
            operand types are: const wchar_t [8] + dcmtk::log4cplus::tstring   c:\DCMTK\include\dcmtk\oflog\tracelog.h
IntelliSense: no operator "+" matches these operands
            operand types are: const wchar_t [8] + dcmtk::log4cplus::tstring   c:\DCMTK\include\dcmtk\oflog\tracelog.h
IntelliSense: identifier "cerr" is undefined   c:\Users\Kyle\Google Drive\cpp_codes\dicom\DicomTest\test1\Source.cpp
IntelliSense: identifier "endl" is undefined   c:\Users\Kyle\Google Drive\cpp_codes\dicom\DicomTest\test1\Source.cpp

如果我设置字符集:使用多字节字符集,我就可以解决问题。

但是我需要在另一个项目中使用DCMTK,其中字符集必须为Unicode。从错误信息来看,问题只出现在某些关于日志记录的类中,这些类可能永远不会被使用:因此,我尝试注释掉引发错误的代码行,现在我可以使用Unicode编译。

这是唯一解决问题的方法吗?如果我注释掉那部分代码会有什么问题吗?


从技术上讲,“字符集”编译器选项是每个文件的选项,因此您可以只更改该选项。但是,也可能会因混合声明而使项目的其余部分混乱,并以其他方式出现问题... - rodrigo
2个回答

2
根据DCMTK的INSTALL文件:
“当定义UNICODE或_UNICODE时,DCMTK无法编译,因为VisualStudio编译器会对所有Windows API函数使用Unicode版本而不是ANSI版本(即对于所有字符字符串参数和返回值使用wchar_t类型而不是char类型)。”
也许,您应该使用动态链接的DCMTK(作为DLL)。然而,这需要使用当前开发快照而不是最新版本(即3.6.0)。

1
我遇到了完全相同的问题。这个帖子已经有几天了,但也许有人可以使用这些信息。我找到了一些类似问题的帖子,但没有令人满意的解决方案。
我们的问题是想将IDE从VS2008更改为VS2015。我们软件解决方案的所有(子)项目都是使用UNICODE标志构建的。而我们之前已经成功地将DCMTK 3.6.1集成到UNICODE项目中。
我下载了最新的DCMTK 3.6.1版本(3.6.1_20161102),并使用VS2015编译它。然后我尝试将静态库链接和编译到我们的软件解决方案中,但这失败了(出现了与上述描述相同的错误)。
在尝试了几个小时无果的情况下,我尝试了另一种方法。因为在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) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in DCMBase.obj
没有这个标志,我能够无问题地使用已编译的静态库。
希望这能帮助某些人并节省大量时间。
问候。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接