Search code examples
c++windowsvisual-studiozxingiconv

Libconv cannot convert argument when compiling zxing


I'm trying to compile the zxing library ported to C++ on Windows 7 (64) using Visual Studio 2015.

I followed the steps described on Readme using Cmake to generate the .sln and .vcxproj files.

However when I build the code I get this error:

Severity Code Description Project File Line Suppression State Error C2664 'size_t libiconv(libiconv_t,const char **,size_t *,char **,size_t *)': cannot convert argument 2 from 'char **' to 'const char **'

At the line:

    iconv(ic, &ss, &sl, &ds, &dl);

And here is a part of the code here the error happend:

#include <zxing/aztec/decoder/Decoder.h>
#ifndef NO_ICONV 
#include <iconv.h>
#endif
#include <iostream>
#include <zxing/FormatException.h>
#include <zxing/common/reedsolomon/ReedSolomonDecoder.h>
#include <zxing/common/reedsolomon/ReedSolomonException.h>
#include <zxing/common/reedsolomon/GenericGF.h>
#include <zxing/common/IllegalArgumentException.h>
#include <zxing/common/DecoderResult.h>
using zxing::aztec::Decoder;
using zxing::DecoderResult;
using zxing::String;
using zxing::BitArray;
using zxing::BitMatrix;
using zxing::Ref;

using std::string;


namespace {
 void add(string& result, char character) {
#ifndef NO_ICONV
  char character2 = character & 0xff;
  char s[] =  {character2};
  char* ss = s;
  size_t sl = sizeof(s);
  char d[4];
  char* ds = d;
  size_t dl = sizeof(d);
  iconv_t ic = iconv_open("UTF-8", "ISO-8859-1");
  iconv(ic, &ss, &sl, &ds, &dl); //<<<< at this line
  iconv_close(ic);
  d[sizeof(d)-dl] = 0;
  result.append(d);
#else
  result.push_back(character);
#endif
}
...

Thanks for your help!


Solution

  • This is the signature of iconv:

    size_t iconv (iconv_t cd,
                  const char* * inbuf, size_t * inbytesleft,
                  char* * outbuf, size_t * outbytesleft);
    

    But you call iconv with a char* as second parameter instead of a const char**.

    Here is a complete example.