# \#define iconv\_open libiconv\_open in libiconv 1.15

**URL:** <https://forum.crystal-lang.org/t/define-iconv-open-libiconv-open-in-libiconv-1-15/706>\
**Category:** Help & Support\
**Created:** [April 28, 2019, 4:13am UTC](https://forum.crystal-lang.org/t/define-iconv-open-libiconv-open-in-libiconv-1-15/706 "2019-04-28T04:13:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![padoauk](https://avatars.discourse-cdn.com/v4/letter/p/e68b1a/32.png) [@padoauk](https://forum.crystal-lang.org/u/padoauk)\
**Post date:** [April 28, 2019, 4:13am UTC](https://forum.crystal-lang.org/t/define-iconv-open-libiconv-open-in-libiconv-1-15/706/1 "2019-04-28T04:13:00Z")

</div>

Hi.

I am new to crystal lang. I want to build the latest version on macOS but have some problems.

```
$ cd crystal-0.28.0
$ make
...
ar -rcs src/ext/libcrystal.a src/ext/sigfault.o
CRYSTAL_CONFIG_PATH="/Volumes/U/Users/ici/work/crystal/crystal-0.28.0/src" CRYSTAL_CONFIG_BUILD_COMMIT="" ./bin/crystal build -D preview_overflow -D compiler_rt -o .build/crystal src/compiler/crystal.cr -D without_openssl -D without_zlib
Undefined symbols for architecture x86_64:
  "_iconv", referenced from:

 ...

ld: symbol(s) not found for architecture x86_64

```

In libiconv 1.15 iconv\_open is a cpp macro to libiconv\_open in iconv.h and, I guess, this is the reason of the above link error of crystal-0.28.0 on macOS with macports libiconv installed. (with llvm 6.0.1)

In crystal-0.28.0, iconv\_open is invoked in src/iconv.cr in the following way.

```
iconv = LibC.iconv_open(to, from)

```

Is this guess right ? Let me know whether the macro defined in iconv.h is applied or how to apply the macro for building crystal on macOS.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![asterite](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/asterite/32/60_2.png) [@asterite](https://forum.crystal-lang.org/u/asterite)\
**Post date:** [April 28, 2019, 10:29am UTC](https://forum.crystal-lang.org/t/define-iconv-open-libiconv-open-in-libiconv-1-15/706/2 "2019-04-28T10:29:36Z")

</div>

There’s no way to run a C macro from Crystal. Can’t you install it using homebrew?

---

<div class="post-metadata">

**Author:** ![padoauk](https://avatars.discourse-cdn.com/v4/letter/p/e68b1a/32.png) [@padoauk](https://forum.crystal-lang.org/u/padoauk)\
**Post date:** [April 28, 2019, 3:09pm UTC](https://forum.crystal-lang.org/t/define-iconv-open-libiconv-open-in-libiconv-1-15/706/3 "2019-04-28T15:09:03Z")

</div>

Thanks for the comment.

I understand that about the C macro. I found that there are two iconvs, one is in /usr/lib and the other is in /opt/local/lib. Since the link options contain -L/opt/local/lib explicitly, /opt/lib/libiconv.a is used for -liconv. If the option is changed from -liconv to /usr/lib/libiconv.a, the link error may not happen.

Let me know how -L/opt/local/lib is acquired in make procedure ? I want to try.

---

<div class="post-metadata">

**Author:** ![asterite](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/asterite/32/60_2.png) [@asterite](https://forum.crystal-lang.org/u/asterite)\
**Post date:** [April 29, 2019, 3:05pm UTC](https://forum.crystal-lang.org/t/define-iconv-open-libiconv-open-in-libiconv-1-15/706/4 "2019-04-29T15:05:27Z")

</div>

> [@padoauk](#):
>
> Since the link options contain -L/opt/local/lib explicitly

Where? I think we don’t pass link options when we compile Crystal. It just gets the default ones (I can’t remember how that works).

---

<div class="post-metadata">

**Author:** ![padoauk](https://avatars.discourse-cdn.com/v4/letter/p/e68b1a/32.png) [@padoauk](https://forum.crystal-lang.org/u/padoauk)\
**Post date:** [April 30, 2019, 3:53am UTC](https://forum.crystal-lang.org/t/define-iconv-open-libiconv-open-in-libiconv-1-15/706/5 "2019-04-30T03:53:48Z")

</div>

I found how to build crystal on macOS. The answer is found in what macports or homebrew does.

Basically, it looks src/lib\_c/x86\_64-macosx-darwin/c/iconv.cr is not good when GNU libiconv, in which iconv\_open is a cpp macro, is used. What they do is to replace the file with amd64-unknown-openbsd/c/iconv.cr.

Now, make of crystal-0.28.0 has successfully finished.

Thank you.
