# trouble with find\_package(iconv) and include(FindIconv) on AIX

**URL:** <https://discourse.cmake.org/t/trouble-with-find-package-iconv-and-include-findiconv-on-aix/2006>\
**Category:** Code\
**Created:** [October 15, 2020, 2:58pm UTC](https://discourse.cmake.org/t/trouble-with-find-package-iconv-and-include-findiconv-on-aix/2006 "2020-10-15T14:58:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![datalogics-robb](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/d/b9e5f3/32.png) [@datalogics-robb](https://discourse.cmake.org/u/datalogics-robb)\
**Post date:** [October 15, 2020, 2:58pm UTC](https://discourse.cmake.org/t/trouble-with-find-package-iconv-and-include-findiconv-on-aix/2006/1 "2020-10-15T14:58:39Z")

</div>

I have discovered (while building Doxygen) that the iconv test fails on AIX with g++ because of incorrect (for AIX) linking. I took the test’s code:

(python-env-nepal) robb@nepal:/raid/proj/procyon/checkouts-procyon/robb/dle-sandbox/conan-doxygen\_installer (master)$ echo "#include \<iconv.h\>

> ```
> int main() {
> iconv(iconv_t(-1), 0, 0, 0, 0);
> }" > iconv_test.cpp
> 
> ```

Build without adding iconv at link time -

(python-env-nepal) robb@nepal:/raid/proj/procyon/checkouts-procyon/robb/dle-sandbox/conan-doxygen\_installer (master)$ g++ -o ictest iconv\_test.cpp  
ld: 0711-317 ERROR: Undefined symbol: .libiconv  
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.  
collect2: error: ld returned 8 exit status

Now just specify -liconv on the link - which works -

(python-env-nepal) robb@nepal:/raid/proj/procyon/checkouts-procyon/robb/dle-sandbox/conan-doxygen\_installer (master)$ g++ -o ictest iconv\_test.cpp -liconv

The link command as produced by CMake (3.18.0 in this case)

(python-env-nepal) robb@nepal:/raid/proj/procyon/checkouts-procyon/robb/dle-sandbox/conan-doxygen\_installer (master)$ /opt/freeware/bin/g++ -maix64 -pthread -maltivec -mvsx -DICONV\_COMPILES -Wl,-bnoipath iconv\_test.cpp -o ictest -Wl,-blibpath:/opt/freeware/lib/gcc/powerpc-ibm-aix7.1.0.0/8/pthread/ppc64:/opt/freeware/lib/pthread/ppc64:/opt/freeware/lib/gcc/powerpc-ibm-aix7.1.0.0/8:/opt/freeware/lib:/usr/lib:/lib /usr/lib/libiconv.a  
ld: 0711-317 ERROR: Undefined symbol: .libiconv  
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.  
collect2: error: ld returned 8 exit status

Here, specifying the full path to the shared library (/usr/lib/libiconv.a is an archive with three shared objects: 32-bit, 64-bit and an older 32-bit version).

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [October 15, 2020, 4:17pm UTC](https://discourse.cmake.org/t/trouble-with-find-package-iconv-and-include-findiconv-on-aix/2006/2 "2020-10-15T16:17:49Z")

</div>

Seems like [`IMPORTED_LIBNAME`](https://cmake.org/cmake/help/latest/prop_tgt/IMPORTED_LIBNAME.html) should be used on AIX then? @brad.king?

---

<div class="post-metadata">

**Author:** ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)\
**Post date:** [October 15, 2020, 4:32pm UTC](https://discourse.cmake.org/t/trouble-with-find-package-iconv-and-include-findiconv-on-aix/2006/3 "2020-10-15T16:32:15Z")

</div>

When using `-liconv`, which library file does the linker choose?

---

<div class="post-metadata">

**Author:** ![datalogics-robb](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/d/b9e5f3/32.png) [@datalogics-robb](https://discourse.cmake.org/u/datalogics-robb)\
**Post date:** [October 15, 2020, 4:55pm UTC](https://discourse.cmake.org/t/trouble-with-find-package-iconv-and-include-findiconv-on-aix/2006/4 "2020-10-15T16:55:53Z")

</div>

Oh, surprise! It’s not using /usr/lib/libiconv.a when it’s specified as -liconv

(python-env-nepal) robb@nepal:/raid/proj/procyon/checkouts-procyon/robb/dle-sandbox/test (develop-18)$ g++ -o iconv\_test -maix64 -pthread iconv\_test.cpp -liconv  
(python-env-nepal) robb@nepal:/raid/proj/procyon/checkouts-procyon/robb/dle-sandbox/test (develop-18)$ ldd iconv\_test  
iconv\_test needs:  
/usr/lib/libc.a(shr\_64.o)  
/usr/lib/libpthreads.a(shr\_xpg5\_64.o)  
/opt/freeware/lib/gcc/powerpc-ibm-aix7.1.0.0/8/…/…/…/libiconv.a(libiconv.so.2)  
/opt/freeware/lib/gcc/powerpc-ibm-aix7.1.0.0/8/pthread/ppc64/libgcc\_s.a(shr.o)  
/opt/freeware/lib/gcc/powerpc-ibm-aix7.1.0.0/8/pthread/ppc64/libstdc++.a(libstdc++.so.6)  
/unix  
/usr/lib/libcrypt.a(shr\_64.o)  
(python-env-nepal) robb@nepal:/raid/proj/procyon/checkouts-procyon/robb/dle-sandbox/test (develop-18)$ g++ -o iconv\_test -maix64 -pthread iconv\_test.cpp -L/usr/lib -liconv  
ld: 0711-317 ERROR: Undefined symbol: .libiconv  
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.  
collect2: error: ld returned 8 exit status

---

<div class="post-metadata">

**Author:** ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)\
**Post date:** [October 16, 2020, 11:50am UTC](https://discourse.cmake.org/t/trouble-with-find-package-iconv-and-include-findiconv-on-aix/2006/5 "2020-10-16T11:50:12Z")

</div>

Thanks. If you’re using the `/opt/freeware` compilers, I suggest also adding that prefix to `CMAKE_PREFIX_PATH`, either as an environment variable or as `-DCMAKE_PREFIX_PATH=/opt/freeware`. That will tell CMake’s find operations to prefer that directory over others on the system.
