MantisBT - CMake
View Issue Details
0008035CMakeCMakepublic2008-11-06 06:522009-01-07 14:57
Jed K Brown 
Brad King 
normalmajoralways
closedno change required 
CMake-2-6 
 
0008035: Make find_library() check PATHS before system directories
I have

/usr/lib/libparmetis.a (built using Open MPI 1.2.8)
/opt/mpich2/lib/libparmetis.a (built using MPICH2 1.1.0a1)

While these define and reference all the same symbols, they are *not* ABI-compatible. For instance sizeof(MPI_Comm) is different. If the wrong version is linked, we will not get any warnings by the build system, but the executable will seg-fault.

# resolves (incorrectly) to /usr/lib/libparmetis.a
find_library (PARMETIS_LIB parmetis PATHS /opt/mpich2/lib)

# resolves to /opt/mpich2/lib/libparmetis.a
find_library (PARMETIS_LIB parmetis HINTS /opt/mpich2/lib)

Many modules use PATHS for what HINTS is intended for, and will resolve all subcomponents to the wrong library when trying to find a version in a non-standard location. The documentation says PATHS should be searched before system directories.
No tags attached.
Issue History
2008-11-06 06:52Jed K BrownNew Issue
2009-01-07 14:36Bill HoffmanStatusnew => assigned
2009-01-07 14:36Bill HoffmanAssigned To => Brad King
2009-01-07 14:57Brad KingNote Added: 0014478
2009-01-07 14:57Brad KingStatusassigned => closed
2009-01-07 14:57Brad KingResolutionopen => no change required

Notes
(0014478)
Brad King   
2009-01-07 14:57   
Where do the docs say PATHS come before system dirs? It is this:

       3. Search the paths specified by the HINTS option. These should be
       paths computed by system introspection, such as a hint provided by the
       location of another item already found. Hard-coded guesses should be
       specified with the PATHS option.

...

       5. Search cmake variables defined in the Platform files for the
       current system. This can be skipped if NO_CMAKE_SYSTEM_PATH is
       passed.

          <prefix>/lib for each <prefix> in CMAKE_SYSTEM_PREFIX_PATH
          CMAKE_SYSTEM_LIBRARY_PATH
          CMAKE_SYSTEM_FRAMEWORK_PATH

       6. Search the paths specified by the PATHS option or in the
       short-hand version of the command. These are typically hard-coded
       guesses.

This means that HINTS come before system dirs and PATHS come after them. The HINTS documentation explicitly states that hard-coded guesses should be PATHS. This is absolutely necessary so that users and system configurations can override hard-coded guesses by setting up their environments correctly. HINTS should only be paths computed from something on the system and never be hard-coded paths.

This is not a bug in find_library. If there is any bug it is either in the find-module containing the line you mention or in the system's configuration (for example linking with -lparmetis will get the wrong one too). If /opt/mpich2 appears in either CMAKE_SYSTEM_PREFIX_PATH or CMAKE_PREFIX_PATH the proper library will be found.