[CMake] Installation corrupts library on OS X
Clinton Stimpson
clinton at elemtech.com
Tue Oct 14 15:56:54 EDT 2014
On Tuesday, October 14, 2014 12:10:36 PM Peter Eastman wrote:
> Hi Clint,
>
> In my case, it wasn't anything like that. I was only specifying
> /usr/local/cuda/lib once. More specifically, my CMakeLists.txt specified
>
> TARGET_LINK_LIBRARIES(${SHARED_TARGET} ${CUDA_LIBRARIES})
>
> where CUDA_LIBRARIES is
>
> /usr/local/cuda/lib/libcudart.dylib-Wl,-rpath-Wl,/usr/local/cuda/lib
Since CMake 2.8.12, CMake will automatically figure out the
-Wl,-rpath-Wl,/usr/local/cuda/lib part for
/usr/local/cuda/lib/libcudart.dylib.
So, the duplicate comes from CMake adding it once, and you adding it once.
You should be able to remove any -Wl,-rpath flags that you add manually with
CMake 2.8.12 and newer, and let CMake take care of that for you.
>
> This library also linked against another of my libraries, that also happened
> to link against CUDA. So that's why it was getting referenced twice: once
> directly, and once indirectly via a second library.
>
> In any case, it's not clear to me why CMake is calling "install_name_tool
> -delete_rpath". Everything works fine without doing that. And when you do
> it, that breaks things.
CMake calls "install_name_tool -delete_rpath" at install time to remove the
build rpaths and add install rpaths as specified by the INSTALL_RPATH target
property.
For more details and examples:
http://www.kitware.com/blog/home/post/510
http://www.cmake.org/Wiki/CMake_RPATH_handling
Clint
>
> Peter
>
> On Oct 14, 2014, at 11:06 AM, Clinton Stimpson <clinton at elemtech.com> wrote:
> > Here's a simple way to reproduce from the command line:
> >
> > echo "void foo() {}" > lib.c
> > gcc -dynamiclib -o libtest.dylib -Wl,-rpath,/usr/lib -Wl,-rpath,/usr/lib
> > lib.c install_name_tool -delete_rpath /usr/lib libtest.dylib
> > otool -L libtest.dylib
> >
> > # gives me the error: "load command 13 size zero (can't advance to other
> >
> > load commands)"
> >
> > At install time, CMake will call "install_name_tool -delete_rpath ... " as
> > needed.
> >
> > I can't get into Apple's bug tracker. I don't know why. When I try to
> > log
> > in, it comes back with a generic error and it asks me to email them with
> > details about the error.
> >
> > When I do the same on Linux, the GNU linker will consolidate the duplicate
> > paths.
> >
> > Thanks!
> >
> > Clint
--
Clinton Stimpson
Elemental Technologies, Inc
Computational Simulation Software, LLC
www.csimsoft.com
More information about the CMake
mailing list