I have developed a library to a target for my project where i am facing an intresting issue related to relative path of CMAKE. During QNX debug build, linker is trying to link lib as absolute path instead of relative path.
Ex:
[100%] Linking CXX executable SampleMain
cd D:/Repo/build-CMake_Sample_inclib-HMI_Qnx-Debug/SampleApp && C:/qnx700/host/win64/x86_64/usr/bin/qcc.exe -Vgcc_ntoaarch64le -lang-c++ -g -g “CMakeFiles/SampleMain.dir/src/main.cpp.o” -o SampleMain -Wl,-rpath,D:/Repo/CMake_Sample_inclib/inclib/lib D:/Repo/CMake_Sample_inclib/inclib/lib/libincrtos.so
The expectation is
[100%] Linking CXX executable SampleMain
cd D:/Repo/build-CMake_Sample_inclib-HMI_Qnx-Debug/SampleApp && C:/qnx700/host/win64/x86_64/usr/bin/qcc.exe -Vgcc_ntoaarch64le -lang-c++ -g -g “CMakeFiles/SampleMain.dir/src/main.cpp.o” -o SampleMain -Wl,-rpath,…/…/CMake_Sample_inclib/inclib/lib /lib/libincrtos.so
You’re overwriting variables all over the place here. You code is the same as:
set(CMAKE_SKIP_RPATH TRUE CACHE BOOL "If set, runtime paths are not added when using shared libraries.")
set(CMAKE_BUILD_RPATH_USE_ORIGIN TRUE)
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH OFF)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
${CMAKE_INSTALL_PREFIX} is almost always going to be an absolute path, so that’s one possible location for the absolute path to come from, though your settings seem to not be using that so much. I would suggest setting CMAKE_BUILD_WITH_INSTALL_RPATH to ON, making the build tree layout look like your install tree and using an install rpath of $ORIGIN/../lib (or something like it).
With the below code, able to get relative path in CMAKE linker stage as shown below. set_property(
** TARGET inclib**
** PROPERTY IMPORTED_NO_SONAME 1**
** )**
Is it direct solution or do we have any deviation in the functionality?
I’d recommend it; it makes your RPATH testing actually useful. It’s not mandatory since CMake has mechanisms to make different RPATH entries for the build and install trees, but, IMO, that just doubles the amount of logic you need to do.
I’m not familiar with this property or its behaviors. It might be the answer or it might just be a side effect. @brad.king?