Mix compile failing on windows for :iconv

I’m trying to use the https://github.com/AlexKovalevych/exoffice library. I has a dependency :iconv which fails to compile on windows:

===> Compiling c:/Elixir/rmas/deps/iconv/c_src/iconv.c
===> Microsoft (R) C/C++ Optimizing Compiler Version 19.10.25019 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

cl : Command line warning D9002 : ignoring unknown option '-g'
c:\program files\erl9.0\erts-9.0\include\erl_drv_nif.h(40): warning C4820: '<unnamed-tag>': '4' bytes padding added after data member 'dirty_scheduler_support'
c:\Program Files\erl9.0\erts-9.0\include\erl_nif.h(103): warning C4820: 'enif_func_t': '4' bytes padding added after data member 'arity'
c:\Program Files\erl9.0\erts-9.0\include\erl_nif.h(105): warning C4820: 'enif_func_t': '4' bytes padding added after data member 'flags'
c:\Program Files\erl9.0\erts-9.0\include\erl_nif.h(114): warning C4820: 'enif_entry_t': '4' bytes padding added after data member 'num_of_funcs'
c:\Program Files\erl9.0\erts-9.0\include\erl_nif.h(127): warning C4820: 'enif_entry_t': '4' bytes padding added after data member 'options'
c:/Elixir/rmas/deps/iconv/c_src/iconv.c(20): fatal error C1083: Cannot open include file: 'iconv.h': No such file or directory

I’m on windows 10, with Visual Studio Community 2017.

i’m running this from the Visual Studio 2017 Developer Command Prompt
[vcvarsall.bat] Environment initialized for: ‘x64’

Any help please.

Since libiconv is a GNU project, I doubt that it will be compilable by anything that’s not clang or gcc at all, but of course you can try to download lib-iconvs sources from https://www.gnu.org/software/libiconv/ and put the headers somewhere where they get found by the MSVCC. Also you’ll need to compile the library itself using the MSVCC and put it somewhere where it can be found when your program runs.

Or you switch to MINGW/cygwin, install libiconv-dev packages (or equivalent) and from then on use that.

Too tedious… considering we only need one or two calls from iconv:

I’ll see if i can swap out convert_encoding for some pure-elixir code

Should do what you want without much fuss…

Pure Elixir


1 Like

Thanks, already trying to use that.

Please how do you decode from “UTF-16LE” to “UTF-8” using this library?

I have tried adding this:
config :codepagex, :encodings, ["VENDORS/MISC/KPS9566"]

… but no luck.

For example, i get this:

[<<80, 0, 70, 0, 65, 0, 81, 0, 67, 0, 82, 0, 49, 0, 48, 0, 49, 0>>, <<48, 0, 51, 0>>, <<85, 0, 66, 0, 65, 0, 32, 0, 80, 0, 76, 0, 67, 0>>, 908734.9299999923]

where i should get this:["PFAQCR101","03", "UBA PLC", 908734.9299999923]

What is your call to codepagex?

Sendt fra min telefon


Sorry. I did not realize you needed utf16. Codepagex wont support this yet.

Please use the builtin module instead :slight_smile:


Sendt fra min telefon

On a quick glance it seems to be correct…

Om a second thought though, and after rereading your conversion direction, I have to correct…

The binaries in your list seem to match an UTF-16BE encoding of the expected result. So can you please show how you try to convert your code from one to other?

I have modified exoffice to use Codepagex in stead of iconv

see my attempt:

just found a better solution:

iex(19)> :unicode.characters_to_binary(<<85, 0, 66, 0, 65, 0, 32, 0, 80, 0, 76, 0, 67, 0>>, {:utf16, :little})

This way i can drop all external character encoding dependencies all together

1 Like

The FileMaker BaseEllemnts plugin project uses iconv and has building instructions for all platforms, including win32 og x64 - See the link for this, and some other libraries as well.

1 Like