# find\_package(PNG) failing to find i386 libs when crosscompiling on x86-64 host?

**URL:** https://discourse.cmake.org/t/find-package-png-failing-to-find-i386-libs-when-crosscompiling-on-x86-64-host/783
**Category:** Usage
**Tags:** os:linux
**Created:** [March 9, 2020, 11:26pm UTC](https://discourse.cmake.org/t/find-package-png-failing-to-find-i386-libs-when-crosscompiling-on-x86-64-host/783 "2020-03-09T23:26:40Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![steven-johnson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/steven-johnson/32/448_2.png) [@steven-johnson](https://discourse.cmake.org/u/steven-johnson)
#### Post date: [March 9, 2020, 11:26pm UTC](https://discourse.cmake.org/t/find-package-png-failing-to-find-i386-libs-when-crosscompiling-on-x86-64-host/783/1 "2020-03-09T23:26:40Z")

</div>

The situation: my host system is an x86-64 linux system (running ubuntu 18). I’m trying to cross-compile (and test) for x86-32 on this system. Most of what I need to do seems straightforward, and has worked fine for a long time; the gotcha is that I can’t seem to get `find_package(PNG)` or `find_package(JPEG)` to find the 32-bit versions that are present on the system.

Mnore details:

My setup for cross-compiling (and cross-testing) is basically:

```auto
sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install \
  gcc-multilib \
  g++-multilib \
  libjpeg-dev:i386 \
  libpng-dev:i386 \
...
export CC="${CC} -m32"
export CXX="${CXX} -m32"
export LD="${LD} -melf_i386"
...
cmake <my normal cmake args> \
       -D CMAKE_FIND_ROOT_PATH=/usr/lib/i386-linux-gnu \
       -D CMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY"

```

I’ve tried adding variations of CMAKE\_MODULE\_PATH, CMAKE\_PREFIX\_PATH, CMAKE\_FIND\_LIBRARY\_CUSTOM\_LIB\_SUFFIX, PNG\_DIR/JPEG\_DIR, and probably other things, but I still end up with `find_package(PNG)` and `find_package(JPEG)` both failing. I’ve verified by inspection that the packages really are there (under /usr/lib/i386-linux-gnu), but CMake refuses to find them, and I can’t figure out any way to get it to be more verbose about telling me why it’s failing.

BTW, this is using cmake version 3.16.2.

Any suggestions here?

---

<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: [March 10, 2020, 12:51pm UTC](https://discourse.cmake.org/t/find-package-png-failing-to-find-i386-libs-when-crosscompiling-on-x86-64-host/783/2 "2020-03-10T12:51:54Z")

</div>

You’re not telling CMake that you’re cross-compiling here. Rather than using `-m32` flags “behind” CMake’s back, try making [a toolchain file](https://cmake.org/cmake/help/v3.6/manual/cmake-toolchains.7.html) (there are also docs on making these around the Web) to let CMake know that you’re cross compiling (you should be able to use `CMAKE_CROSSCOMPILING_EMULATOR` set to the empty string (not undefined) to indicate that the resulting binaries are natively executable).

---

<div class="post-metadata">

### Author: ![steven-johnson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/steven-johnson/32/448_2.png) [@steven-johnson](https://discourse.cmake.org/u/steven-johnson)
#### Post date: [March 10, 2020, 9:06pm UTC](https://discourse.cmake.org/t/find-package-png-failing-to-find-i386-libs-when-crosscompiling-on-x86-64-host/783/3 "2020-03-10T21:06:04Z")

</div>

I had to try a lot of different sources to piece together what I needed for a toolchain file – yes, there are many docs on the web, but none of them seem particularly definitive or exhaustive. (The CMake doc page could be improved by adding more examples.)

That said, this seems to be working for my use case so far:

```auto
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR i686)

set(CMAKE_CXX_FLAGS_INIT -m32)
set(CMAKE_C_FLAGS_INIT -m32)

set(CMAKE_EXE_LINKER_FLAGS_INIT -m32)
set(CMAKE_SHARED_LINKER_FLAGS_INIT -m32)
set(CMAKE_MODULE_LINKER_FLAGS_INIT -m32)

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

# Set to empty string to indicate the resulting binaries can be natively executed
set(CMAKE_CROSSCOMPILING_EMULATOR )

```

---

<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: [March 10, 2020, 9:47pm UTC](https://discourse.cmake.org/t/find-package-png-failing-to-find-i386-libs-when-crosscompiling-on-x86-64-host/783/4 "2020-03-10T21:47:49Z")

</div>

Ah, sorry for the aimless direction; I haven’t done many toolchain files myself. The `#cmake` Slack channel on `cpplang.slack.com` has folks who are more knowledgeable than I about that specific topic at least.

> [@steven-johnson](#):
>
> The CMake doc page could be improved by adding more examples

Do you have specific feedback to this end? The x86\_64 → ix86 case seems common enough to just have an example, but any other details would be useful to help us improve the docs.

---

<div class="post-metadata">

### Author: ![alex](https://discourse.cmake.org/user_avatar/discourse.cmake.org/alex/32/125_2.png) [@alex](https://discourse.cmake.org/u/alex)
#### Post date: [March 10, 2020, 10:29pm UTC](https://discourse.cmake.org/t/find-package-png-failing-to-find-i386-libs-when-crosscompiling-on-x86-64-host/783/5 "2020-03-10T22:29:58Z")

</div>

> [@ben.boeckel](#):
>
> The `#cmake` Slack channel on `cpplang.slack.com`

How does one get an invitation to that Slack channel?

---

<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: [March 11, 2020, 11:54am UTC](https://discourse.cmake.org/t/find-package-png-failing-to-find-i386-libs-when-crosscompiling-on-x86-64-host/783/6 "2020-03-11T11:54:22Z")

</div>

I think you just join it once you have an account using the sidebar. I don’t think there’s any invite-only status on it.

---

<div class="post-metadata">

### Author: ![alex](https://discourse.cmake.org/user_avatar/discourse.cmake.org/alex/32/125_2.png) [@alex](https://discourse.cmake.org/u/alex)
#### Post date: [March 13, 2020, 3:54am UTC](https://discourse.cmake.org/t/find-package-png-failing-to-find-i386-libs-when-crosscompiling-on-x86-64-host/783/7 "2020-03-13T03:54:55Z")

</div>

Turns out you go here: [https://cpplang-inviter.cppalliance.org/](https://cpplang-inviter.cppalliance.org/)
