[CMake] Simple (?) problem with libraries & executable dependencies

Carminati Federico Federico.Carminati at cern.ch
Mon Feb 14 22:19:38 EST 2011


Hello Michael,
   thanks a lot for looking into my problem. It turns out that Mac OS X behaves a bit oddly, in the sense that the name of the directory of installation is in the libraries as well as in the executable. I solved the problem with a single line setting the properties of the library in the following way:

  set_target_properties(${PACKAGE} PROPERTIES INSTALL_NAME_DIR ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})

Best regards, 

Federico Carminati
CERN-PH 
1211 Geneva 23
Switzerland
Tel: +41 22 76 74959
Fax: +41 22 76 68505
Mobile: +41 76 487 4843



On 15 Feb 2011, at 03:21, Michael Hertling wrote:

> On 02/14/2011 03:11 AM, Carminati Federico wrote:
>> Hello Michael,
>>    thanks for your answer. Indeed it is a very complex built system, so the link line is
>> 
>> /opt/gcc-4.5.1/bin/g++    -DDarwin -DDATE_SYS=Darwin -Dlong32='int' -Dlong64='long long' -DdatePointer='long' -O -g -pipe -fbounds-check -fsigned-char -fno-common -fmessage-length=0 -fno-default-inline -fno-inline -I/usr/X11R6/include -I/usr/local/include -D_REENTRANT -pthread -m64 -Wall -Wno-long-long -W -Weffc++ -Wshadow -Woverloaded-virtual -ansi -bind_at_load -Wl,-search_paths_first -Wl,-headerpad_max_install_names  CMakeFiles/aliroot.dir/fpu.c.o CMakeFiles/aliroot.dir/aliroot.cxx.o  -o ../bin/tgt_macosx64/aliroot  -L/usr/local/AliRoot/NewIO/macosx64/lib/tgt_macosx64 ../lib/tgt_macosx64/libMUONevaluation.so ../lib/tgt_macosx64/libMUONmapping.so ../lib/tgt_macosx64/libMUONshuttle.so ../lib/tgt_macosx64/libMUONgraphics.so ../lib/tgt_macosx64/libMUONsim.so ../lib/tgt_macosx64/libMUONrec.so ../lib/tgt_macosx64/libMUONgeometry.so ../lib/tgt_macosx64/libMUONcalib.so ../lib/tgt_macosx64/libMUONbase.so ../lib/tgt_macosx64/libMUONraw.so ../lib/tgt_macosx64/libMUONtrigger.so ../l
> ib/tgt_macosx64/libMUONcore.so ../lib/tgt_macosx64/libTPCbase.so ../lib/tgt_macosx64/libTPCsim.so ../lib/tgt_macosx64/libTPCrec.so ../lib/tgt_macosx64/libTPCfast.so ../lib/tgt_macosx64/libITSbase.so ../lib/tgt_macosx64/libITSsim.so ../lib/tgt_macosx64/libITSrec.so ../lib/tgt_macosx64/libPMDbase.so ../lib/tgt_macosx64/libPMDsim.so ../lib/tgt_macosx64/libPMDrec.so ../lib/tgt_macosx64/libTRDbase.so ../lib/tgt_macosx64/libTRDsim.so ../lib/tgt_macosx64/libTRDrec.so ../lib/tgt_macosx64/libFMDbase.so ../lib/tgt_macosx64/libFMDsim.so ../lib/tgt_macosx64/libFMDrec.so ../lib/tgt_macosx64/libTOFbase.so ../lib/tgt_macosx64/libTOFrec.so ../lib/tgt_macosx64/libTOFsim.so ../lib/tgt_macosx64/libPHOSUtils.so ../lib/tgt_macosx64/libPHOSbase.so ../lib/tgt_macosx64/libPHOSsim.so ../lib/tgt_macosx64/libPHOSrec.so ../lib/tgt_macosx64/libACORDEbase.so ../lib/tgt_macosx64/libACORDEsim.so ../lib/tgt_macosx64/libACORDErec.so ../lib/tgt_macosx64/libHMPIDbase.so ../lib/tgt_macosx64/libHMPIDrec.so ../lib
> /tgt_macosx64/libHMPIDsim.so ../lib/tgt_macosx64/libZDCbase.so ../lib/tgt_macosx64/libZDCsim.so ../lib/tgt_macosx64/libZDCrec.so ../lib/tgt_macosx64/libVZERObase.so ../lib/tgt_macosx64/libVZEROsim.so ../lib/tgt_macosx64/libVZEROrec.so ../lib/tgt_macosx64/libEMCALUtils.so ../lib/tgt_macosx64/libEMCALbase.so ../lib/tgt_macosx64/libEMCALsim.so ../lib/tgt_macosx64/libEMCALrec.so ../lib/tgt_macosx64/libBCM.so ../lib/tgt_macosx64/libSTRUCT.so ../lib/tgt_macosx64/libT0base.so ../lib/tgt_macosx64/libT0sim.so ../lib/tgt_macosx64/libT0rec.so ../lib/tgt_macosx64/libFASTSIM.so ../lib/tgt_macosx64/libmicrocern.so ../lib/tgt_macosx64/libHLTbase.so ../lib/tgt_macosx64/libTRIGGERbase.so ../lib/tgt_macosx64/libSTEER.so ../lib/tgt_macosx64/libSTAT.so ../lib/tgt_macosx64/libCDB.so ../lib/tgt_macosx64/libAOD.so ../lib/tgt_macosx64/libSTEERBase.so ../lib/tgt_macosx64/libESD.so ../lib/tgt_macosx64/libRAWDatasim.so ../lib/tgt_macosx64/libRAWDatarec.so ../lib/tgt_macosx64/libRAWDatabase.so ../lib/tg
> t_macosx64/libEVGEN.so -L/usr/local/root/macosx64/lib -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lGui -pthread -Wl,-rpath,/usr/local/root/macosx64/lib -lm -ldl -lThread -lMinuit -lVMC -lEG -lGeom -lTreePlayer -lXMLIO -lXMLParser -lProof -lProofPlayer -lMLP -lSpectrum -L/usr/local/root/macosx64/lib/5.29/ -L/usr/X11R6/lib -lX11 -ldl /opt/gcc-4.5.1/lib/gcc/x86_64-apple-darwin10/4.5.1/../../../libgfortran.dylib /opt/gcc-4.5.1/lib/gcc/x86_64-apple-darwin10/4.5.1/libgfortranbegin.a -bind_at_load -lThread -lGui -lm -lMinuit -lVMC -lEG -lGeom -lTreePlayer -lXMLIO -lXMLParser -lProof -lProofPlayer -lMLP -lSpectrum -lX11 /opt/gcc-4.5.1/lib/gcc/x86_64-apple-darwin10/4.5.1/../../../libgfortran.dylib /opt/gcc-4.5.1/lib/gcc/x86_64-apple-darwin10/4.5.1/libgfortranbegin.a 
>> 
>> after I have installed it, if I run it fails
>> 
>> [/Users/fca] aliroot
>> dyld: Library not loaded: libMUONevaluation.so
>>  Referenced from: /usr/local/AliRoot/NewIO/bin/tgt_macosx64/aliroot
>>  Reason: image not found
>> Trace/BPT trap (core dumped)
>> [/Users/fca] echo $LD_LIBRARY_PATH
>> :/usr/local/root/macosx64/lib:.:/usr/local/AliRoot/NewIO/lib/tgt_macosx64:/usr/local/AliRoot/geant3/lib/tgt_macosx64:/lib/tgt_macosx64:/usr/local/cuda/lib
>> [/Users/fca] ls -l /usr/local/AliRoot/NewIO/lib/tgt_macosx64/libMUONevaluation.so 
>> -rwxr-xr-x  1 fca  z2  789760 Feb 14 02:51 /usr/local/AliRoot/NewIO/lib/tgt_macosx64/libMUONevaluation.so*
>> 
>> while it I use -l instead of the path, the executable works, but, as I said, it is not updated. The library is defined with
>> 
>>  add_library(Mylib SHARED sources)
>>  set_target_properties(MylibPROPERTIES SUFFIX .so)  
>> 
>> I am reading now the pages you kindly pointed me too. Best regards, 
> 
> At first sight, everything looks OK, but I'm no MacOSXpert. ;)
> 
> Spontaneously, I'd suggest to try the following:
> 
> - Use "otool -L" on the executable and the library to check the paths.
> - Throw away the build tree and start anew from an empty directory.
> - Start the executable from within the library's directory, i.e.:
> 
> cd /usr/local/AliRoot/NewIO/lib/tgt_macosx64
> /usr/local/AliRoot/NewIO/bin/tgt_macosx64/aliroot
> 
> Apart from that, perhaps a MacOSX specialist on this ML can help.
> 
> Regards,
> 
> Michael
> 
>> On 14 Feb 2011, at 02:26, Michael Hertling wrote:
>> 
>>> On 02/14/2011 01:32 AM, Carminati Federico wrote:
>>>> Hello,
>>>>  I have a problem with the dependencies of an executable. The executable depends on a number of shared libraries. If I define the executable like this
>>>> 
>>>> 
>>>> add_executable(aliroot aliroot.cxx)
>>>> target_link_libraries(aliroot Mylib)
>>>> 
>>>> then the link command really looks like
>>>> 
>>>> g++ -o aliroot ../lib/libMylib.so
>>>> 
>>>> and I have plenty of problems with relocation and rpaths. [...]
>>> 
>>> Which problems do you have exactly? Could you post an excerpt from the
>>> output of "make VERBOSE=1" that shows the issue in more detail? Have
>>> you already read [1]? How is the target "Mylib" defined?
>>> 
>>>> [...] If I just do
>>>> 
>>>> target_link_libraries(aliroot -lMylib)
>>>> 
>>>> the link command looks "right":
>>>> 
>>>> g++ -o aliroot -lMylib
>>>> 
>>>> however the executable is NOT relinked in case a library is recreated. [...]
>>> 
>>> No, this isn't right, not really. Besides other things - linker search
>>> paths [2], selection of static/shared libraries [3] - the "-lMylib" is
>>> taken verbatim and CMake does not recognize that you're aiming at your
>>> project's Mylib target. So, the dependency of aliroot on Mylib doesn't
>>> hold anymore and the executable isn't relinked when the library has
>>> been rebuilt.
>>> 
>>>> [...] I even tried to do 
>>>> 
>>>> add_dependencies(aliroot <path to the library>/libMylib.so)
>>>> 
>>>> but it does not work. [...]
>>> 
>>> ADD_DEPENDENCIES() only works on targets, not on files.
>>> 
>>>> [...] Any hint? Thanks!
>>> 
>>> [1] http://www.cmake.org/Wiki/CMake_RPATH_handling
>>> [2] http://www.cmake.org/pipermail/cmake/2011-January/041647.html
>>> [3] http://www.cmake.org/Wiki/CMake_2.6_Notes#Link_Line_Generation
>>> 
>>> Regards,
>>> 
>>> Michael
> _______________________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
> 
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake



More information about the CMake mailing list