View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0015963CMakeCMakepublic2016-02-09 16:522016-06-10 14:21
ReporterBruce Adams 
Assigned To 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionno change required 
PlatformLinuxOSRedHatOS Version5, 6 & 7
Product VersionCMake 3.4.3 
Target VersionFixed in Version 
Summary0015963: strange behaviour running readlink via execute_process
DescriptionI'm trying to use readlink -f to get the absolute path to a shared library following all symlinks.

>readlink -f /opt/gcc4.9.3/lib64/libstdc++.so.6
/opt/gcc4.9.3/lib64/libstdc++.so.6.0.20

but when I do this in cmake it doesn't expand the full path E.g.

set(CPP11_PATH ${CMAKE_CURRENT_BINARY_DIR}/)
execute_process(COMMAND ldd ${CPP11_PATH} COMMAND grep libstdc++ COMMAND awk "{ print $3; }" OUTPUT_VARIABLE LIBSTDCPP_PATH)
message("LIBSTDCPP_PATH=${LIBSTDCPP_PATH}")
execute_process(COMMAND readlink -f ${LIBSTDCPP_PATH} OUTPUT_VARIABLE LIBSTDCPP_ABSPATH)
message("LIBSTDCPP_ABSPATH=${LIBSTDCPP_ABSPATH}")

prints:

LIBSTDCPP_PATH=/opt/gcc4.9.3/lib64/libstdc++.so.6
LIBSTDCPP_ABSPATH=/opt/gcc4.9.3/lib64/libstdc++.so.6

This also happens if I wrap it in a shell script:

execute_process(COMMAND doreadlink.sh ${LIBSTDCPP_PATH} OUTPUT_VARIABLE LIBSTDCPP_ABSPATH2)
message("LIBSTDCPP_ABSPATH2=${LIBSTDCPP_ABSPATH2}")

>LIBSTDCPP_ABSPATH2=/opt/gcc4.9.3/lib64/libstdc++.so.6


Steps To Reproducecmake_minimum_required(VERSION 2.8)
project(TEST CXX)
CMake script as below

set(CPP11_PATH ${CMAKE_CURRENT_BINARY_DIR}/cpp11)
execute_process(COMMAND g++ ${CMAKE_CURRENT_SOURCE_DIR}/cpp11.cpp -o${CPP11_PATH})

execute_process(COMMAND ldd ${CPP11_PATH} COMMAND grep libstdc++ COMMAND awk "{ print $3; }" OUTPUT_VARIABLE LIBSTDCPP_PATH)
message("LIBSTDCPP_PATH=${LIBSTDCPP_PATH}")
execute_process(COMMAND readlink -f ${LIBSTDCPP_PATH} OUTPUT_VARIABLE LIBSTDCPP_ABSPATH)
message("LIBSTDCPP_ABSPATH=${LIBSTDCPP_ABSPATH}")
Additional InformationThe following is an effective work around

execute_process(COMMAND ldd ${CPP11_PATH} COMMAND grep libstdc++ COMMAND awk "{ print $3; }" COMMAND xargs readlink -f OUTPUT_VARIABLE LIBSTDCPP_PATH)

Originally raised on stackoverflow:

http://stackoverflow.com/questions/35299970/strange-behaviour-with-readlink-under-cmake [^]
TagsNo tags attached.
Attached Files

 Relationships

  Notes
(0040456)
Bruce Adams (reporter)
2016-02-09 16:56

I can't think how this could be a bug. It must be some misunderstanding on my part as to how cmake works but it is not at all obvious what.
(0040457)
Bruce Adams (reporter)
2016-02-09 17:52

This is user error not a bug. Please close. Sorry for wasting bandwidth!

awk "{ print $3; }"

adds a newline which causes readlink to return the original string rather than
expanding it.

awk "{ printf($3); }"

makes everything work as expected.
The same behaviour occurs using get_filename_component realpath.
(0041259)
Kitware Robot (administrator)
2016-06-10 14:21

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.

 Issue History
Date Modified Username Field Change
2016-02-09 16:52 Bruce Adams New Issue
2016-02-09 16:56 Bruce Adams Note Added: 0040456
2016-02-09 17:52 Bruce Adams Note Added: 0040457
2016-02-10 08:55 Brad King Status new => resolved
2016-02-10 08:55 Brad King Resolution open => no change required
2016-06-10 14:21 Kitware Robot Note Added: 0041259
2016-06-10 14:21 Kitware Robot Status resolved => closed


Copyright © 2000 - 2018 MantisBT Team