GitHub issue: Can we build a library in the target environment?
State: closed

Hi there.

I have observed that when I link a library (opencvlibs) which is built on my source system, the submission package passes all the checks and gives meaningful results.

However when I try to run the `run_validate11.sh` file on a VM created using iso image [provided here on line 89](https://pages.nist.gov/frvt/api/FRVT_common.pdf), the linker gives a problem
as follows

```
/usr/bin/ld: warning: libopencv_dnn.so.408, needed by ../../../lib/libfrvt_11_company_000.so, not found (try using -rpath or -rpath-link)
```

Even after providing -rpath as follows before linking the target with the opencv libraries, the same issue prevails

```
# Create a variable for opencv package name
set(ocv_name opencv_48)
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,-rpath,${CMAKE_CURRENT_SOURCE_DIR}/../../lib/${ocv_name}/lib/")
```

Can someone guide me how to overcome this issue? Can we build opencv in the target environment on the fly while initializing the environment? This would take a lot of time since compiling and building opencv is a really difficult task. However I was wondering  if there is a simpler solution that can help me in this situation.

Would be grateful for any help, thanks a lot!

Can you use a relative RPATH instead? You can also change your RPATH to '.' or whatever is relevant with `chrpath`

Hi @xsacha 

Thanks for the prompt response.

So, here is how my lib is structured

![image](https://github.com/usnistgov/frvt/assets/45599762/09e77854-a7bb-4f90-90a1-a320ecd3ca65)

I have tried the following options in my CMakeLists.txt file in the src/nullImpl folder

```
# Option 1
set (CMAKE_SHARED_LINKER_FLAGS "-Wl,-rpath-link,$ORIGIN/opencv_42/lib")

# Option 2
set (CMAKE_SHARED_LINKER_FLAGS "-Wl,-rpath,$ORIGIN/opencv_42/lib")

# Option 3
set(ocv_name opencv_42)
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,-rpath-link,${CMAKE_CURRENT_SOURCE_DIR}/../../lib/${ocv_name}/lib/")

#Option 4
set(ocv_name opencv_42)
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,-rpath,${CMAKE_CURRENT_SOURCE_DIR}/../../lib/${ocv_name}/lib/")
```

When I do chrpath, I can see that the rpath is set appropriately as expected

![image](https://github.com/usnistgov/frvt/assets/45599762/5c9a18cb-d951-48ca-af9a-cb257554adb6)

Also the libraries for libopencv_dnn, libopencv_imgproc etc. are present in the proper locations as seen below

![image](https://github.com/usnistgov/frvt/assets/45599762/d2aa0647-28a4-46d8-a0d8-79073e457690)

However when executing the `run_validate_11.sh` file, these libraries are not fetched...

Could you suggest how can I debug this issue further? I have tried several things but nothing has succeeded so far...



I would say your chrpath is showing that the RPATH is misconfigured. For example if you move the library to another path, does it still work? It looks like a full path in the output.
You can also change the rpath to a relative path.

Try this: move the libraries and bin to a different path as the validation would do and then check if it works. If it works, no problem.

Thanks for the comment, indeed it was misconfigured.

Now I think it is configured correctly as I can see that it is showing origin correctly in the rpath of the exeutable.

![image](https://github.com/usnistgov/frvt/assets/45599762/e86beede-b5e2-405c-92bb-ed4af184bd25)

However, still some opencv libraries are not being picked up despite their presence in the libs folder as shown in the following folder structure

![image](https://github.com/usnistgov/frvt/assets/45599762/06247b35-2ec9-4c6c-8ed4-72829f1f2fb9)

![image](https://github.com/usnistgov/frvt/assets/45599762/ec9f6676-07da-47fa-916d-941834205343)

Hi @xsacha ,

If I do an ldd to check if all the libraries are linked properly against the submission library, I get the following output

![image](https://github.com/usnistgov/frvt/assets/45599762/a4d3eafe-1772-4dcf-9bc1-24fa88a89f25)

It is linking with all the libraries properly except `libopencv_imgproc.so`, any ideas why would that be? The library exists in the same path as `libopencv_dnn.so` and `libopencv_core.so` which are there in the same directory as `libopencv_imgproc.so`.

Any idea on what might be going wrong? This same thing works fine when I test on my local machine but on the VM built using ISO provided by NIST, I encounter this issue...

Thanks,
Vinayak.

Solved this issue. After inspecting which files are not linked to my submission library I found that the opencv libraries were not linked and this was happening because the LD_LIBRARY_PATH was set only to frvt/11/lib.

Keeping all the opencv libraries in lib folder in a flat format helped solve this issue.

@ElisonSherton Can you give some hint on how you changed the CMakeLists.txt since I am facing the same issue as well. My folder structure inside lib folder is as follows:
lib:
       libfrvt_nullimpl.so
       opencv_folder
       onnxruntime_folder
opencv and onnxruntime ".so" files are inside the opencv_folder/build/lib and onnxruntime_folder/build/Linux/Release/ folders respectively.

Also did you set the ldd_library_path to frvt/11/lib and moved all the opencv libraries to that folder? If so then how did you edit the cmakelists.txt?

Hey @rishidd11,

If you're facing the same issue as me, then this may help you.

LD_LIBRARY_PATH is already set by NIST to point to the `frvt/11/lib` folder [as seen here](https://github.com/usnistgov/frvt/blob/b6b23da12b8d814d96a63e69179133e6972c20e2/11/run_validate_11.sh#L23), so I did not manually change it or make any changes to CMakeLists.txt for linking purposes. I do assume that libs are stored in the `frvt/11/lib` location and accordingly set my paths.

Instead from the opencv_folder/build/lib (as in your case), I took all of the .so files and kept them inside the `frvt/11/lib` folders. That made my code work as expected.

Hope this helps.

Thanks,
Vinayak.