0

When building via cmake, the linker outputs the following lines:

[35%] Linking CXX shared library libexample.so
...
[47%] Linking CXX executable ../folder/program

My understanding is that the printed path of the shared object or executable is relative to the working directory.

Is there any way to tell the linker to output absolute path?

Such output would be desirable:

[35%] Linking CXX shared library /absolute/libexample.so
...
[47%] Linking CXX executable /absolute/folder/program

I need the absolute path to parse and use it further. In the context where the parsing takes place, the working directory is unfortunately not directly known.

wrf
  • 56
  • 4
  • The paths afaik are relative to the build directory used for the configuration. Using the command line output for the "further processing" doesn't seem to be a good idea to me. Depending on the setyp of your project you're able to determine the location where cmake outputs the binaries via `CMAKE_RUNTIME_OUTPUT_DIRECTORY`, `CMAKE_LIBRARY_OUTPUT_DIRECTORY` ect. or better still install it locally using `cmake --install build_dir --prefix install_root_dir` – fabian Apr 26 '22 at 16:54
  • "I need the absolute path to parse and use it further. In the context where the parsing takes place, the working directory is unfortunately not directly known." - Normal output is for humans only. If you want to automatically parse it for extract some information, then it is better to use file `compile_commands.json`. That file is generated by CMake when set variable `CMAKE_EXPORT_COMPILE_COMMANDS`: https://stackoverflow.com/questions/23960835/cmake-not-generating-compile-commands-json – Tsyvarev Apr 26 '22 at 17:32
  • compile_commands.json would be a good idea in principle, but unfortunately it does not work with MSVC: https://cmake.org/cmake/help/latest/variable/CMAKE_EXPORT_COMPILE_COMMANDS.html "This option is implemented only by Makefile Generators and the Ninja. It is ignored on other generators." – wrf Apr 29 '22 at 08:44

0 Answers0