cromod
cromod

Reputation: 1809

Weird error with "cmake -E create_symlink"

When I update the source files of my project configured on cmake and launch again make command in the build directory, I get a weird and not very explicit error message after linking.

The create_symlink command seems to be involved (make VERBOSE=1) :

[100%] Building CXX object CMakeFiles/thing.dir/main.cpp.o
Linking CXX executable thing
/usr/bin/cmake -E cmake_link_script CMakeFiles/thing.dir/link.txt --verbose=1
/usr/bin/c++       CMakeFiles/thing.dir/main.cpp.o  -o thing -rdynamic 
/usr/bin/cmake -E create_symlink /path/to/stuff/ stufflink
make[2]: *** [thing] Error 1
make[2]: Leaving directory « /home/cromod/bug/build »
make[1]: *** [CMakeFiles/thing.dir/all] Erreur 2
make[1]: Leaving directory « /home/cromod/bug/build »
make: *** [all] Error 2

The executable seems to be correctly compiled and linked because I can use it without problem. Besides another make command makes the error message disappear.

Here's a simple cmake script to reproduce this case :

cmake_minimum_required(VERSION 2.8)
project(thing)
add_executable(thing main.cpp)
set(STUFF_PATH "/path/to/stuff/")
add_custom_command(TARGET thing POST_BUILD COMMAND ${CMAKE_COMMAND} -E create_symlink ${STUFF_PATH} stufflink)

I'm forced to run this cmake script on debian 7 / cmake 2.8.9 (among other platforms) :(

Why does create_symlink fail ? Do you know a mean to avoid this bug with cmake 2.8 ?

Upvotes: 1

Views: 2958

Answers (1)

cromod
cromod

Reputation: 1809

In fact, I met an edge case of the create_symlink command on cmake 2.8.

The specific path /path/to/stuff doesn't exist on the platform with the weird error so stufflink is a broken symbolic link.

On old cmake versions (<3.0.0), when cmake -E create_symlink ... tries to rewrite a broken symlink, it returns 1 without any explicit error message.

This bug is related to those issues found in the bug tracker of cmake and their resolution (in cmake 3.0.0) fixes my case too :

As I'm forced to run my cmake script on several platform, I'll add an environment variable to define /path/to/stuff.

Upvotes: 3

Related Questions