0

I'm trying to build zxing using MinGW, but it fails with error undefined reference to libiconv_close

This is the output of the build:

scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
g++ -o build\zxing.exe -Ldl -L/usr/lib -LC:/MinGW/msys/1.0/local/lib -liconv build\magick\src\MagickBitmapSource.o build\magick\src\main.o build\libzxing.a -lMagick++ -lMagickWand -lMagickCore
build\libzxing.a(Decoder.o): In function `add':
C:\Workspace\BarCodes\zxing-2.1\cpp/build/core/src/zxing/aztec/decoder/Decoder.cpp:51: undefined reference to `libiconv_open'
C:\Workspace\BarCodes\zxing-2.1\cpp/build/core/src/zxing/aztec/decoder/Decoder.cpp:52: undefined reference to `libiconv'
C:\Workspace\BarCodes\zxing-2.1\cpp/build/core/src/zxing/aztec/decoder/Decoder.cpp:53: undefined reference to `libiconv_close'
build\libzxing.a(DecodedBitStreamParser.o): In function `ZN5zxing6qrcode22DecodedBitStreamParser6appendERSsPKhjPKc':
C:\Workspace\BarCodes\zxing-2.1\cpp/build/core/src/zxing/qrcode/decoder/DecodedBitStreamParser.cpp:70: undefined reference to `libiconv_open'
C:\Workspace\BarCodes\zxing-2.1\cpp/build/core/src/zxing/qrcode/decoder/DecodedBitStreamParser.cpp:85: undefined reference to `libiconv'
C:\Workspace\BarCodes\zxing-2.1\cpp/build/core/src/zxing/qrcode/decoder/DecodedBitStreamParser.cpp:87: undefined reference to `libiconv_close'
C:\Workspace\BarCodes\zxing-2.1\cpp/build/core/src/zxing/qrcode/decoder/DecodedBitStreamParser.cpp:92: undefined reference to `libiconv_close'
collect2: ld returned 1 exit status
scons: *** [build\zxing.exe] Error 1
scons: building terminated because of errors.
sashoalm
  • 75,001
  • 122
  • 434
  • 781
  • Can we see your SCons build scripts? – Brady Nov 01 '12 at 15:15
  • I don't know anything about libiconv, but are you sure that you're linking against the correct version? That could cause a problem like this, if the old version doesn't have the same symbols... – Xymostech Nov 01 '12 at 15:15
  • 1
    `-liconv` needs to go after the zxing archive in the link command. – Mat Nov 01 '12 at 15:17
  • @Mat Sorry, I did not understand that. What did you mean by 'zxing archive'? – sashoalm Nov 01 '12 at 15:34
  • this thing: `build\libzxing.a`, see e.g. http://stackoverflow.com/questions/10000925/opengl-linux-undefined-reference-to-basic-functions - this has been mentioned in lots of posts here, link order can matter. – Mat Nov 01 '12 at 15:35
  • Thanks, that fixed it. Could you post it as answer then? – sashoalm Nov 01 '12 at 15:48

1 Answers1

0

The problem was because of link order, -liconv needed to go after build\libzxing.a in the command line, as @Mat said.

sashoalm
  • 75,001
  • 122
  • 434
  • 781