Saviz
(Saviz Mohammadi)
March 28, 2024, 2:11am
1
According to the CMake documentation, we can use the following command to copy DLL files to the binary directory under the Windows operating system:
if(WIN32)
add_custom_command(TARGET ${EXECUTABLE_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_RUNTIME_DLLS:${EXECUTABLE_NAME}>
$<TARGET_FILE_DIR:${EXECUTABLE_NAME}>
COMMAND_EXPAND_LISTS
COMMENT "Copying DLLs to target directory")
endif()
However, for MacOS and Linux operating systems, the process isn’t as straightforward. I was wondering if there is something similar in nature for them as well?
MacOS and Linux have RPATH so you don’t need to copy SHARED libraries into the same directory as your executable. Windows lacks RPATH functionality.
In computing, rpath designates the run-time search path hard-coded in an executable file or library. Dynamic linking loaders use the rpath to find required libraries.
Specifically, it encodes a path to shared libraries into the header of an executable (or another shared library). This RPATH header value (so named in the Executable and Linkable Format header standards) may either override or supplement the system default dynamic linking search paths.
The rpath of an executable or shared library...
1 Like
Saviz
(Saviz Mohammadi)
April 1, 2024, 5:02am
3
Great, so I don’t need to copy anything. But, do I need to include any special command to instruct the system to take advantage of RPATH or are they just self aware?
IIRC by default RPATH will be used in the build tree when it’s available.
1 Like