# Creating appimage for OpenModelica: File not found error (binary patching needed?)

**URL:** https://discourse.appimage.org/t/creating-appimage-for-openmodelica-file-not-found-error-binary-patching-needed/311
**Category:** Creating AppImages
**Created:** [March 22, 2018, 7:03pm UTC](https://discourse.appimage.org/t/creating-appimage-for-openmodelica-file-not-found-error-binary-patching-needed/311 "2018-03-22T19:03:32Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![gntech](https://avatars.discourse-cdn.com/v4/letter/g/a3d4f5/32.png) [@gntech](https://discourse.appimage.org/u/gntech)
#### Post date: [March 22, 2018, 7:03pm UTC](https://discourse.appimage.org/t/creating-appimage-for-openmodelica-file-not-found-error-binary-patching-needed/311/1 "2018-03-22T19:03:32Z")

</div>

I am building an appimage of [OpenModelica](https://openmodelica.org/) which is initially quite easy since it is available as a deb-repository.

See my receipe here: [https://github.com/gntech/AppImages/blob/add-openmodelica-receipe/recipes/OpenModelica.yml](https://github.com/gntech/AppImages/blob/add-openmodelica-receipe/recipes/OpenModelica.yml)

The appimage builds fine but when I start the app and open “Tools/OpenModelica Compiler CLI” I get the following error message:

```
Error: File not Found: /usr/lib/omc/ModelicaBuiltin.mo.

```

However when I extract the appimage into a folder I can see that file is at the location it should be. I suspect that this has something to do with absolute vs relative search paths?

As you can see in my recipe I have tried the following attempt at binary patching (inspired from the FreeCAD recipe) But it does not work.

```
- find usr/ -type f -exec sed -i -e "s@/usr/lib/omc@././/usr/lib/omc@g" {} \;
```

---

<div class="post-metadata">

### Author: ![probono](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.appimage.org/probono/32/81_2.png) [@probono](https://discourse.appimage.org/u/probono)
#### Post date: [March 27, 2018, 7:26am UTC](https://discourse.appimage.org/t/creating-appimage-for-openmodelica-file-not-found-error-binary-patching-needed/311/2 "2018-03-27T07:26:17Z")

</div>

Best is not to use absolute paths to load resources, but paths relative to the main binary.

If you want to go patch pre-existing binaries: Please do not put usr in the replacement, like in the examples. When the AppImage is executed, we do a chdir() into usr/ in the AppImage.

---

<div class="post-metadata">

### Author: ![overheadhunter](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.appimage.org/overheadhunter/32/128_2.png) [@overheadhunter](https://discourse.appimage.org/u/overheadhunter)
#### Post date: [March 29, 2018, 8:31am UTC](https://discourse.appimage.org/t/creating-appimage-for-openmodelica-file-not-found-error-binary-patching-needed/311/3 "2018-03-29T08:31:18Z")

</div>

> [@probono](#):
>
> When the AppImage is executed, we do a chdir() into usr/ in the AppImage.

Which btw isn’t well documented. 😉

Don’t want to hijack the thread, but what’s the rationale behind switching to `usr/`?

---

<div class="post-metadata">

### Author: ![probono](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.appimage.org/probono/32/81_2.png) [@probono](https://discourse.appimage.org/u/probono)
#### Post date: [March 29, 2018, 3:01pm UTC](https://discourse.appimage.org/t/creating-appimage-for-openmodelica-file-not-found-error-binary-patching-needed/311/4 "2018-03-29T15:01:02Z")

</div>

The payload application binary must not contain any hardcoded paths that would prevent it from being relocatable. You can check this by running strings `MyApp.AppDir/usr/bin/myapp | grep /usr`. Should this return something, then you need to modify your app programmatically (i.e., by changing the source code).

If you prefer not to change the source code of your app and/or would not like to recompile your app, you can also patch the binary, for example using the command `sed -i -e 's|/usr|././|g' MyApp.AppDir/usr/bin/myapp`. **To make this kind of binary patching possible** , `AppRun.c` does a `chdir()` into `usr/` in the AppImage prior to executing the main payload application.

---

<div class="post-metadata">

### Author: ![overheadhunter](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.appimage.org/overheadhunter/32/128_2.png) [@overheadhunter](https://discourse.appimage.org/u/overheadhunter)
#### Post date: [March 29, 2018, 7:19pm UTC](https://discourse.appimage.org/t/creating-appimage-for-openmodelica-file-not-found-error-binary-patching-needed/311/5 "2018-03-29T19:19:42Z")

</div>

> [@probono](#):
>
> If you prefer not to change the source code of your app and/or would not like to recompile your app, you can also patch the binary, for example using the command sed -i -e ‘s|/usr|././|g’ MyApp.AppDir/usr/bin/myapp. To make this kind of binary patching possible, AppRun.c does a chdir() into usr/ in the AppImage prior to executing the main payload application.

Ok let me rephrase this to make sure I got it right:

Patching only just works, because `/usr` and `././` has the same length. Otherwise it would screw up the binary. Replacing `/usr` by `usr` or `./usr` is therefore not possible. That’s why we want to be in `usr/` and not in the AppDir’s root.

---

<div class="post-metadata">

### Author: ![probono](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.appimage.org/probono/32/81_2.png) [@probono](https://discourse.appimage.org/u/probono)
#### Post date: [March 31, 2018, 3:31am UTC](https://discourse.appimage.org/t/creating-appimage-for-openmodelica-file-not-found-error-binary-patching-needed/311/6 "2018-03-31T03:31:20Z")

</div>

Exactly. This is correct.
