Problem: I am creating an external project in CMake. The project has a Makefile that ultimately creates a shared object. I want to link and set this object in my super project, as if it were one of the libraries in the project. The problem is that the ExternalProject library connects to my applications and libraries with a relative path, and not with an absolute path, which causes problems when starting from any directory other than where CMake puts it.
I have created a sample SSCCE sample project to demonstrate my general setup. Feel free to learn and compile if necessary ( git clone https://github.com/calebwherry/cmake-SO-question-main --recursive && cd cmake-SO-question-main && mkdir build && cd build && cmake .. && make && cd src/app/testApp && ldd testApp ).
Whenever I run ldd in the executable and libs, I get the output as follows:
linux-vdso.so.1 => (0x00007fff8b5a2000) libTestLib.so => /home/jwherry3/repos/cmake-superprj-main-test/build/src/lib/TestLib/libTestLib.so (0x00007f592da57000) ../../lib/libExtLib.so (0x00007f592d855000) libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f592d539000) libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f592d2b7000) libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f592d0a0000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f592cd14000) /lib64/ld-linux-x86-64.so.2 (0x00007f592dc5a000)
I tried all sorts of things related to RPATHS, but cannot get ExtLib to reference correctly. The library local to the project ( libTestLib.so ) is very simple.
I also tried setting LD_LIBRARY_PATH to override the relative path when the application starts, but even when I do this, it still cannot find the library. I suppose because it is relative, does it not correspond to the normal order of binding? The result is that the binary will not work if I do not get into the directory in which it is located.
It seems to me that I am doing something really stupid when creating dependencies with ExternalProject, and this is my problem, but I hit my head for 3 days and did not come up with anything.
System setup: Debian Wheezy 64-bit, CMake 3.0.2, g ++ - 4.9.2.
Caleb source share