[CMake] Cmake not using user configured lib for linking
Wang Wei
wangwei at comp.nus.edu.sg
Wed Oct 19 03:25:33 EDT 2016
I am using cmake (3.5.0) to compile a C++ probject on Ubuntu 14.04, which
depends on Nvidia Cudnn. It seems that the cmake does not provide the
correct paths of cudnn to the linker although I have configured the paths.
File FindCUDNN.cmake:
FIND_PATH(CUDNN_INCLUDE_DIR NAME "cudnn.h" PATHS "$ENV{CMAKE_INCLUDE_PATH}")
FIND_LIBRARY(CUDNN_LIBRARIES NAME "libcudnn.so" PATHS
"$ENV{CMAKE_LIBRARY_PATH}")
INCLUDE(FindPackageHandleStandardArgs)
find_package_handle_standard_args(CUDNN DEFAULT_MSG CUDNN_INCLUDE_DIR
CUDNN_LIBRARIES)
MARK_AS_ADVANCED(CUDNN_INCLUDE_DIR CUDNN_LIBRARIES)
CMakeLists.txt:
FIND_PACKAGE(CUDNN REQUIRED)
LIST(APPEND LINKER_LIBS ${CUDNN_LIBRARIES})
...
ADD_LIBRARY(myobjects OBJECT ${mysources})
ADD_LIBRARY(mylib SHARED $<TARGET_OBJECTS:myobjects> ${cuda_objs})
TARGET_LINK_LIBRARIES(mylib ${LINKER_LIBS})
CMAKE_INCLUDE_PATH, CMAKE_LIBRARY_PATH are exported to the paths of cudnn5
in my home folder. After cmake .., the paths in CmakeCache.txt are set to
cudnn5. However, the linker (and link.txt) uses -lcudnn without paths to
cudnn5. Consequently, it links the cudnn4 in the system folder, i.e.
/usr/local/cuda/lib64.
Note: If there is no cudnn4 in my system folder, everything is fine. The
link.txt file and the output of make VERBOSE=1 use the absolute paths of
cudnn 5 during linking.
Thanks.
Wei.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20161019/3501ecc4/attachment.html>
More information about the CMake
mailing list