Hi there, I’m trying to make a simple OpenCV Linux application but it works only on OpenCV installed OS, so I wan’t to copy all of it’s dependencies into build folder via cmake to make it also work on the other computers as well without installing opencv on them.
So
I have red this topic: Copying dependent DLLs to executable directory?
But I can’t use “file(GET_RUNTIME_DEPENDENCIES…)” command in my try.
Could you please show me the changes to make to achieve copying all required libs into build folder.
You need to, after the executable is built, run a CMake script which does file(GET_RUNTIME_DEPENDENCIES) on the executable. This gets you a list of paths to libraries needed by the executable which can then be filtered before doing configure_file(${src} ${dest} COPY_ONLY) into your build tree.
Thank you,
So should I create a new CMakelLists.txt file on build directory ?
How can I use file(GET_RUNTIME_DEPENDENCIES) and configure_file(${src} ${dest} COPY_ONLY)
lines to perform that the created executable “DisplayImage” gets all of its dependencies copied into build?
Could You please write the CMakelLists.txt script, that you’ve mentioned before, for this example.
I’m totally beginner and I can learn mostly from working examples, I’ll be pleased for your answers.
And how can I link the executable “DisplayImage” with copied ones instead of which are under /usr/lib and its subdirectories ?
I can’t guarantee this is fully working, but it’s a sketch:
file(GET_RUNTIME_DEPENDENCIES
EXECUTABLES "${exe_path}"
RESOLVED_DEPENDENCIES_VAR found_deps
UNRESOLVED_DEPENDENCIES_VAR unfound_deps)
if (unfound_deps)
# not all required libraries found, probably error
endif ()
foreach (found_dep IN LISTS found_deps)
# Determine if the dep library should be copied.
if (dep_not_wanted)
continue()
endif ()
configure_file("${found_dep}" "${dest_libdir}" COPY_ONLY)
endforeach ()
file(TOUCH "${tagfile}")
I have found one line terminal command to get all dependecies:
ldd | grep “=> /” | awk ‘{print $3}’ | xargs -I ‘{}’ cp -v ‘{}’
But this only copies into a specified folder, after that we must set some environment variables on the target pc. But I want that the dependencies are located on a subfolder of executables location so that where ever I put the main folder it still finds its libraries without searching env variables.
Much obliged for your answer,
I’ve created a CMakelists.txt file in another folder out of project and just copied the executable “DisplayImage” in it and copied your answer into the CMakelists.txt, changed string ‘myexe’ with ‘DisplayImage’ and also I changed ‘${exe_path}’ to ‘./DisplayImage’
but since my CMake Version is 3.5, some commands couldn’t work well.
I’ll try it later.
Thank you very much:)