0

I have setup with build directory set to ./bin within source root. Everything works until I change ./bin to symbolic link. Then everything configures correctly but make starts complaining about not found source files:

make[2]: *** No rule to make target '../cpp/foo.cpp', needed by 'CMakeFiles/mylib.dir/cpp/foo.cpp.o'.

Why it happens and what could I do about it? I had idea to convert this path to absolute (inside makefile) and dump it to console in order to figure-out where it points to but it turned out that this "build.cmake" is recreated automatically at every make invocation :(

ardabro
  • 1,907
  • 16
  • 31
  • 1
    As you can see, CMake generates **relative** paths for files in the source directory: `../cpp/foo.cpp`. Being referred from the build directory, this path becomes incorrect when build directory is symbolic link. Instead of symlinking the build directory, just use **real directory** as a build one. – Tsyvarev Feb 16 '20 at 13:37
  • But in command line I'm able to go back or refer to parent with '..' after I went there using link and it points to the place I started from - as expected. – ardabro Feb 16 '20 at 14:21
  • 1
    "But in command line I'm able to go back or refer to parent with '..' after I went there using link and it points to the place I started from" - This is true only for `cd` command which is processed by `bash` (or whatever shell you use). Other commands - `ls`, `cat`, etc. - doesn't "remember" symlinks when follow upper directories. Just checked that. (The things are more funny: when type `cat ../source/` the bash autocompletes the path, but resulted `cat ../source/main.txt` prints `No such file or directory`). – Tsyvarev Feb 16 '20 at 19:00
  • 1
    Instead of symlinks to directory you may try to use **bind mount** (https://unix.stackexchange.com/questions/198590/what-is-a-bind-mount). This kind of "link" is preserved not only by the bash, but by the Linux kernel too. So things should work. (But I didn't tested that). – Tsyvarev Feb 16 '20 at 19:02

2 Answers2

0

Thanks to Tsyvarev I realized that it is unmovable OS constraint with potential workaround using mount bind

ardabro
  • 1,907
  • 16
  • 31
0

I needed to do the same on a Mac (to exclude the build directory from iCloud Drive) and had success with executing the cmake-command from the build directory (not going there via link) and giving the absolute path for the source to cmake.

See also: https://stackoverflow.com/a/24435795/4883924

Gerriet
  • 1,302
  • 14
  • 20