2014-12-18 3 views
0

Boost의 program_options 라이브러리를 사용하여 라이브러리에 간단한 명령 행 응용 프로그램을 작성하려고했지만 정말 이상한 오류가 발생합니다. Here's 모든 문제의 코드 (예, 정말 간단 키우면) :부스트 컴파일 오류로 부스트 program_options 사용하지 못했습니다.

#include <iostream> 
#include <stdexcept> 
#include <string> 
#include <boost/program_options.hpp> 
#include "NCDocEngineInterop.h" 
#include "NCDocumentEngine.h" 
#include "NCConfigurationManager.h" 
#include "NCAcquisitions.h" 

namespace po = boost::program_options; 
using std::cout; 
using std::cerr; 
using std::endl; 
using std::domain_error; 
using std::wstring; 

void fail_if_empty(const po::variables_map& variables, const char* field) { 
    if (!(variables.count(field))) { 
     cerr << field << " is required, you must provide a value for it" << endl; 
     throw domain_error(field); 
    } 
} 

int main(int ac, char* av[]) 
{ 

    const char* nsdk_path_option = "nsdk-path"; // NC_CONFIGURATION::NC_NSDK_PATH 
    const char* ocr_path_option = "ocr-path"; // NC_CONFIGURATION::NC_OCR_PATH 
    const char* parser_path_option = "parser-path-option"; // NC_CONFIGURATION::NC_PARSER_PATH 
    const char* pdf_path = "pdf-path"; // NC_CONFIGURATION::NC_PDF_PATH 
    const char* output_directory = "output-directory"; 
    const char* input_file = "input-file"; 

    po::options_description description("Runs the NDSK engine at the provided files"); 
    description.add_options() 
     ("help", "produce help message") 
     (nsdk_path_option, po::value<wstring>(), "path to the NSDK") 
     (ocr_path_option, po::value<wstring>(), "path to the OCR") 
     (parser_path_option, po::value<wstring>(), "path to the parser") 
     (pdf_path, po::value<wstring>(),"path to the PDF processor") 
     (output_directory, po::value<wstring>(), "path to the folder where the output will be stored") 
     (input_file, po::value<wstring>(), "path to the input file") 
    ; 

    po::variables_map vm; 
    po::store(po::parse_command_line(ac, av, description), vm); 
    po::notify(vm); 

    fail_if_empty(vm, nsdk_path_option); 
    fail_if_empty(vm, ocr_path_option); 
    fail_if_empty(vm, parser_path_option); 
    fail_if_empty(vm, pdf_path); 
    fail_if_empty(vm, output_directory); 
    fail_if_empty(vm, input_file); 

    NCConfigurationManager::ncSetConfiguration(
     NC_NSDK_PATH, 
     vm[nsdk_path_option].as<wstring>()); 
    NCConfigurationManager::ncSetConfiguration(
     NC_OCR_PATH, 
     vm[ocr_path_option].as<wstring>()); 
    NCConfigurationManager::ncSetConfiguration(
     NC_PARSER_PATH, 
     vm[parser_path_option].as<wstring>()); 
    NCConfigurationManager::ncSetConfiguration(
     NC_PDF_PATH, 
     vm[pdf_path].as<wstring>()); 

    return 0; 
} 

일어나는 컴파일 오류는 다음과 같습니다

오류 오류 C2679 : 이진 '< <' 'const src'유형의 오른쪽 피연산자 (또는 허용 가능한 변환이 없음)을 취하는 연산자를 찾을 수 없습니다. c : \ work \ dev \ source \ src \ framework \ thirdparty \ boost \ boost \ lexical_cast.hpp 1281 1 DocumentProcessor

오류 오류 C2228 : 왼쪽에 '.fail'클래스/구조체/유니온 c : \ work \ digitalbp \ projects \ releasedev \ nsdk_4_0 \ dev \ source \ src \ framework \ thirdparty \ boost \ boost \ lexical_cast.hpp 1281이 있어야합니다. 1 DocumentProcessor

lexical_cast.hpp file here을 볼 수 있습니다.

그리고 여기에 무슨 일이 일어나고 있는지, 왜이 코드에서이 오류가 발생하는지 알 수 없습니다. 나는 부스트 1.50.0을 사용하고 있으며 지금은 업그레이드 할 수 없다. 저는 Visual Studio 2010을 사용하여 빌드하고 있습니다.

그리고 출력 창의 출력 here's :

1>c:\work\src\framework\thirdparty\boost\boost\lexical_cast.hpp(1281): error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'const src' (or there is no acceptable conversion) 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(679): could be 'std::basic_ostream<_Elem,_Traits> &std::operator <<<wchar_t,std::char_traits<wchar_t>>(std::basic_ostream<_Elem,_Traits> &,const char *)' [found using argument-dependent lookup] 
1>   with 
1>   [ 
1>    _Elem=wchar_t, 
1>    _Traits=std::char_traits<wchar_t> 
1>   ] 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(726): or  'std::basic_ostream<_Elem,_Traits> &std::operator <<<wchar_t,std::char_traits<wchar_t>>(std::basic_ostream<_Elem,_Traits> &,char)' [found using argument-dependent lookup] 
1>   with 
1>   [ 
1>    _Elem=wchar_t, 
1>    _Traits=std::char_traits<wchar_t> 
1>   ] 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(968): or  'std::basic_ostream<_Elem,_Traits> &std::operator <<<wchar_t,std::char_traits<wchar_t>,const InputStreamable>(std::basic_ostream<_Elem,_Traits> &&,_Ty)' [found using argument-dependent lookup] 
1>   with 
1>   [ 
1>    _Elem=wchar_t, 
1>    _Traits=std::char_traits<wchar_t>, 
1>    InputStreamable=src, 
1>    _Ty=src 
1>   ] 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(1085): or  'std::basic_ostream<_Elem,_Traits> &std::operator <<<wchar_t,std::char_traits<wchar_t>>(std::basic_ostream<_Elem,_Traits> &,const std::error_code &)' [found using argument-dependent lookup] 
1>   with 
1>   [ 
1>    _Elem=wchar_t, 
1>    _Traits=std::char_traits<wchar_t> 
1>   ] 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(186): or  'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_ostream<_Elem,_Traits> &(__cdecl *)(std::basic_ostream<_Elem,_Traits> &))' 
1>   with 
1>   [ 
1>    _Elem=wchar_t, 
1>    _Traits=std::char_traits<wchar_t> 
1>   ] 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(192): or  'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_ios<_Elem,_Traits> &(__cdecl *)(std::basic_ios<_Elem,_Traits> &))' 
1>   with 
1>   [ 
1>    _Elem=wchar_t, 
1>    _Traits=std::char_traits<wchar_t> 
1>   ] 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(199): or  'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::ios_base &(__cdecl *)(std::ios_base &))' 
1>   with 
1>   [ 
1>    _Elem=wchar_t, 
1>    _Traits=std::char_traits<wchar_t> 
1>   ] 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(206): or  'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::_Bool)' 
1>   with 
1>   [ 
1>    _Elem=wchar_t, 
1>    _Traits=std::char_traits<wchar_t> 
1>   ] 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(226): or  'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(short)' 
1>   with 
1>   [ 
1>    _Elem=wchar_t, 
1>    _Traits=std::char_traits<wchar_t> 
1>   ] 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(260): or  'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned short)' 
1>   with 
1>   [ 
1>    _Elem=wchar_t, 
1>    _Traits=std::char_traits<wchar_t> 
1>   ] 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(280): or  'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(int)' 
1>   with 
1>   [ 
1>    _Elem=wchar_t, 
1>    _Traits=std::char_traits<wchar_t> 
1>   ] 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(305): or  'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned int)' 
1>   with 
1>   [ 
1>    _Elem=wchar_t, 
1>    _Traits=std::char_traits<wchar_t> 
1>   ] 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(325): or  'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(long)' 
1>   with 
1>   [ 
1>    _Elem=wchar_t, 
1>    _Traits=std::char_traits<wchar_t> 
1>   ] 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(345): or  'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned long)' 
1>   with 
1>   [ 
1>    _Elem=wchar_t, 
1>    _Traits=std::char_traits<wchar_t> 
1>   ] 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(366): or  'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(__int64)' 
1>   with 
1>   [ 
1>    _Elem=wchar_t, 
1>    _Traits=std::char_traits<wchar_t> 
1>   ] 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(386): or  'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned __int64)' 
1>   with 
1>   [ 
1>    _Elem=wchar_t, 
1>    _Traits=std::char_traits<wchar_t> 
1>   ] 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(407): or  'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(float)' 
1>   with 
1>   [ 
1>    _Elem=wchar_t, 
1>    _Traits=std::char_traits<wchar_t> 
1>   ] 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(427): or  'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(double)' 
1>   with 
1>   [ 
1>    _Elem=wchar_t, 
1>    _Traits=std::char_traits<wchar_t> 
1>   ] 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(447): or  'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(long double)' 
1>   with 
1>   [ 
1>    _Elem=wchar_t, 
1>    _Traits=std::char_traits<wchar_t> 
1>   ] 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(467): or  'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(const void *)' 
1>   with 
1>   [ 
1>    _Elem=wchar_t, 
1>    _Traits=std::char_traits<wchar_t> 
1>   ] 
1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(487): or  'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_streambuf<_Elem,_Traits> *)' 
1>   with 
1>   [ 
1>    _Elem=wchar_t, 
1>    _Traits=std::char_traits<wchar_t> 
1>   ] 
1>   while trying to match the argument list '(std::basic_ostringstream<_Elem,_Traits,_Alloc>, const src)' 
1>   with 
1>   [ 
1>    _Elem=wchar_t, 
1>    _Traits=std::char_traits<wchar_t>, 
1>    _Alloc=std::allocator<wchar_t> 
1>   ] 
1>   c:\work\src\framework\thirdparty\boost\boost\lexical_cast.hpp(1499) : see reference to function template instantiation 'bool boost::detail::lexical_stream_limited_src<CharT,Traits,RequiresStringbuffer>::shl_input_streamable<const InStreamable>(InputStreamable &)' being compiled 
1>   with 
1>   [ 
1>    CharT=char_type, 
1>    Traits=traits, 
1>    RequiresStringbuffer=true, 
1>    InStreamable=src, 
1>    InputStreamable=src 
1>   ] 
1>   c:\work\src\framework\thirdparty\boost\boost\lexical_cast.hpp(1974) : see reference to function template instantiation 'bool boost::detail::lexical_stream_limited_src<CharT,Traits,RequiresStringbuffer>::operator <<<Source>(const InStreamable &)' being compiled 
1>   with 
1>   [ 
1>    CharT=char_type, 
1>    Traits=traits, 
1>    RequiresStringbuffer=true, 
1>    Source=src, 
1>    InStreamable=src 
1>   ] 
1>   c:\work\src\framework\thirdparty\boost\boost\lexical_cast.hpp(1921) : while compiling class template member function 'std::wstring boost::detail::lexical_cast_do_cast<Target,Source>::lexical_cast_impl(const Source &)' 
1>   with 
1>   [ 
1>    Target=std::wstring, 
1>    Source=src 
1>   ] 
1>   c:\work\src\framework\thirdparty\boost\boost\lexical_cast.hpp(2133) : see reference to class template instantiation 'boost::detail::lexical_cast_do_cast<Target,Source>' being compiled 
1>   with 
1>   [ 
1>    Target=std::wstring, 
1>    Source=src 
1>   ] 
1>   c:\work\src\framework\thirdparty\boost\boost\program_options\detail\value_semantic.hpp(89) : see reference to function template instantiation 'Target boost::lexical_cast<T,std::basic_string<_Elem,_Traits,_Ax>>(const Source &)' being compiled 
1>   with 
1>   [ 
1>    Target=std::wstring, 
1>    T=std::wstring, 
1>    _Elem=char, 
1>    _Traits=std::char_traits<char>, 
1>    _Ax=std::allocator<char>, 
1>    Source=std::basic_string<char,std::char_traits<char>,std::allocator<char>> 
1>   ] 
1>   c:\work\src\framework\thirdparty\boost\boost\program_options\detail\value_semantic.hpp(170) : see reference to function template instantiation 'void boost::program_options::validate<T,char>(boost::any &,const std::vector<_Ty> &,T *,long)' being compiled 
1>   with 
1>   [ 
1>    T=std::wstring, 
1>    _Ty=std::string 
1>   ] 
1>   c:\work\src\framework\thirdparty\boost\boost\program_options\detail\value_semantic.hpp(163) : while compiling class template member function 'void boost::program_options::typed_value<T,charT>::xparse(boost::any &,const std::vector<_Ty> &) const' 
1>   with 
1>   [ 
1>    T=std::wstring, 
1>    charT=char, 
1>    _Ty=std::string 
1>   ] 
1>   c:\work\src\samples\cpp\documentprocessor\documentprocessor\main.cpp(37) : see reference to class template instantiation 'boost::program_options::typed_value<T,charT>' being compiled 
1>   with 
1>   [ 
1>    T=std::wstring, 
1>    charT=char 
1>   ] 
1>c:\work\src\framework\thirdparty\boost\boost\lexical_cast.hpp(1281): error C2228: left of '.fail' must have class/struct/union 
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ========== 
+0

이인가요 유일한 오류 메시지가 있습니까? 그렇지 않은 경우 모든 컴파일 오류 메시지를 게시하십시오 – Mahesh

+0

같은 위치에 다른 오류 메시지가 있습니다. 포함 된 파일 –

+0

출력 창을보고 오류의 전체 템플릿 인스턴스화 컨텍스트를 게시하십시오 .. – Cameron

답변

2

문제는 실제로 여기에 있습니다 :

po::store(po::parse_command_line(ac, av, description), vm); 

parse_command_line 차트는 물론 char하지 wchar_t의 인 basic_command_line_parser<charT> instanciates 때문에 avchar**입니다. 즉, options_description의 모든 문자열은 basic_string<char> 일 필요합니다. 즉 std::string이 아니고 std::wstring이 아님을 의미합니다.

명령 줄 옵션이 항상 오래된 오래된 "c"문자열로 도착하기 때문에 실제로 생각하면 이해할 수 있습니다. mbcs로 인코딩 된 경우에도 올바른 로켈을 사용하여 변환을 수행하는 것은 귀하의 책임입니다. MBCS의 해석은 로케일 고유이므로 유감스럽게도이 작업이 필요합니다.

나는 당신이 wmain()에서 그것을 사용하고 싶었 경우 options_description의 wchar_t의 버전 (생성하는 것이 가능하지만, 그렇지 않은 경우에 볼 수있는 모양을했다. options_description는 하드 std::string의이 포함되어 있습니다.

multi-byte strings reference

+0

굉장! 감사! –