[CMake] Mixing static and dynamic library

Michael Hertling mhertling at online.de
Sat Oct 15 04:46:55 EDT 2011


On 10/13/2011 03:27 PM, pellegrini wrote:
> Hi all,
> 
> I would like to port a hardcoded build line from an old make file to my 
> CMakeLists.txt file for a fortran 90
> project using ifort compiler.
> The line is the following:
> 
>     ifort *.o -o myexec -static-intel -Bstatic -lXm -Bdynamic -lXt
> 
> First, if I get it right (sorry for my ignorance but I come from the 
> python world where I was quite
> preserved from these lines !!!), the goal is to build an executable:
>     - statically bound to the intel libraries
>     - statically bound to libXm library
>     - dynamically bound to libXt library
> 
> A "locate" told me that on my machine both Xt and Xm are in dynamic form 
> (libXm.so.2, libXt.so.6) and in a standard location (/usr/lib). So in my 
> CMakeLists.txt file, I tried:
> 
> set(CMAKE_Fortran_FLAGS_RELEASE "-static-intel")
> add_executable(myexec $SOURCES)
> target_link_libraries(myexec -Bdynamic Xm Xt)
> 
> when building the project I get an error at link time (ld: cannot find 
> -lXm).
> 
> Would you have any idea of what is going wrong with my settings ?
> 
> thanks a lot
> 
> Eric

The message "ld: cannot find -lXm" reveals that the linker can't find
libXm.so - or libXm.a if not ruled out - in the directories searched
for libraries; the mere presence of the SONAMEd libXm.so.2  does not
suffice unless you tell CMake to use it, e.g. via imported libraries
and appropriate IMPORTED_LOCATION properties. Typically, you have a
symlink libXm.so -> libXm.so.2 or to the actual library file, so the
-lXm is sufficient for the linker to succeed, but this symlink isn't
necessary to execute a program linked against the Motif library, and
sometimes it is dropped when the package's development component is
not installed. Thus, could you check if there is a libXm.so symlink?
If not, create it and try anew, and if it still does not work, could
you post the relevant part of the "make VERBOSE=1" output for further
investigation?

Regards,

Michael


More information about the CMake mailing list