我使用的是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:\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如果我设置了Character Set: Use Multi-Byte Character Set,我可以解决这个问题
但是我需要在另一个项目中使用DCMTK,该项目的字符集必须是Unicode。看一下这个错误,问题只出现在一些我可能永远不会用到的日志类中:所以我尝试注释得到错误的代码行,现在我可以用Unicode编译了。
这是解决问题的唯一方法吗?我评论这部分会有什么问题呢?
发布于 2015-02-13 02:36:47
根据DCMTK的安装文件:
“VisualStudio编译器在定义UNICODE或_UNICODE时不会编译,因为DCMTK编译器会对所有Windows API函数使用Unicode版本而不是ANSI版本(即,对于所有字符串参数和返回值,键入wchar_t而不是char )。”
也许,您应该将DCMTK与动态链接一起使用(作为DLL)。但是,这需要使用当前的开发快照,而不是最新版本( 3.6.0)。
发布于 2016-12-17 00:30:44
我遇到了完全相同的问题。这个帖子已经有几天了,但也许有人可以使用这个信息。我发现了一些有类似问题的线程,但没有令人满意的解决方案。
我们遇到了将集成开发环境从VS2008更改为VS2015的问题。我们软件解决方案的所有(子)项目都是使用UNICODE标志构建的。我们之前已经在UNICODE项目中成功地集成了DCMTK 3.6.1。
我下载了最新的DCMTK3.6.1 build (3.6.1_20161102),并用VS2015编译了它。然后,我尝试将静态库链接并编译到我们的软件解决方案中,但失败了(出现了与上面描述的错误相同的错误)。
在尝试了几个小时的静态库、不同的CMake设置和共享库建议(还有一个完整的共享DCMTK库)之后,我尝试了另一种方法。因为通过VS2008集成开发环境和UNICODE,它已经可以正常工作了。
最后,我成功了,因为我使用了较旧的DCMTK3.6.1 build (3.6.1_20120222).
DCMTK 3.6.1 (20120222)
此构建不包含以下文件:
Tracelog.h
dcmtk\oflog\tracelog.h
当为目标项目设置UNICODE标志时,该文件会导致(在我的例子中)编译器和链接器错误。
此外,当标志DCMTK_OVERWRITE_WIN32_COMPILER_FLAGS被激活时,我收到如下错误:
1>dcmnet.lib(assoc.obj):错误LNK2038:检测到‘RuntimeLibrary’不匹配:值'MTd_StaticDebug‘与DCMBase.obj中的值'MDd_DynamicDebug’不匹配
没有这个标志,我就可以毫无问题地使用编译后的静态库。
希望这对某些人有帮助,可以节省很多时间。
问候
https://stackoverflow.com/questions/28106665
复制相似问题