1
name: my-lib
apps:
  library-sample:
    command: library_sample $SNAP/arg_file.json

parts:
  library:
    source: https://github.com/the/sample.git
    plugin: cmake
    install: |
      cp -r samples/library_sample $SNAPCRAFT_PART_INSTALL/
      cp -r ../src/samples/src/arg_file.json $SNAPCRAFT_PART_INSTALL/
      cp --parents modules/dep_lib1/libdep_lib1.so $SNAPCRAFT_PART_INSTALL/
      cp --parents modules/dep_lib2/libdep_lib2.so $SNAPCRAFT_PART_INSTALL/

When I create this snap, I am able to run my-lib.library_sample. However, when the sample tries to load the dependency libraries using a relative path, it fails using the path ./modules/dep_lib1/libdep_lib1.so

My install folder looks as I expect:

parts/library/install/
|-- arg_file.json
|-- library-sample
|-- include
|   |-- ...
|-- lib
|   |-- ...
|-- modules
    |-- dep_lib1
    |   |-- libdep_lib1.so
    |-- dep_lib2
        |-- libdep_lib2.so

If you look at the command: for library-sample:, you can see that I needed to prefix the relative path with $SNAP in order to get the sample to load arg_file.json correctly. However, there are relative paths specified for the dependency libraries inside the argument file that I cannot prefix.

How can I resolve relative paths from within a snap package?

Anthon
  • 69,918
  • 32
  • 186
  • 246
Zak
  • 12,213
  • 21
  • 59
  • 105
  • I'm not seeing anything problematic there-- relative paths should work just fine. How exactly is the library being loaded? What error is occurring? – kyrofa Apr 19 '17 at 01:08
  • `dlopen("./modules/dep_lib1/libdep_lib1.so", RTLD_LAZY);` – Zak Apr 19 '17 at 01:19
  • I believe relative paths in `dlopen` are relative to the current working directory, not the location of the binary calling it. – kyrofa Apr 19 '17 at 01:23
  • @Kyle You are correct! Thank you. I was not going to figure that out on my own. Put it in an answer, and I'll give you the check mark. – Zak Apr 19 '17 at 14:53

1 Answers1

1

Relative paths in dlopen are relative to the current working directory, not the location of the binary calling it. Make sure you account for that.

kyrofa
  • 1,759
  • 1
  • 14
  • 19