CMake FIND_LIBRARY: link to specified library erro

2019-06-21 23:05发布

问题:

I have already installed the FFTW3 library on my computer and the following files could be found in /usr/lib:

libfftw3f.so.3          libfftw3l_threads.so.3
libfftw3f.so.3.3.0      libfftw3l_threads.so.3.3.0
libfftw3f_threads.so.3      libfftw3.so.3
libfftw3f_threads.so.3.3.0  libfftw3.so.3.3.0
libfftw3l.so.3          libfftw3_threads.so.3
libfftw3l.so.3.3.0      libfftw3_threads.so.3.3.0

I want to install another package that needs to link these libraries, but when I try FIND_LIBRARY(FFTW3_LIBRARIES fftw3) and FIND_LIBRARY(FFTW3_LIBRARIES fftw3f), it just cannot find the libraries.

How can I solve this? Thanks!

Code in CMakeLists.txt:

FIND_PATH(FFTW3_INCLUDE_DIR fftw3.h)
IF(FFLD_HOGPYRAMID_DOUBLE)
  FIND_LIBRARY(FFTW3_LIBRARIES libfftw3.so.3)
ELSE()
  FIND_LIBRARY(FFTW3_LIBRARIES libfftw3f.so.3)
ENDIF()
#IF(NOT FFTW3_INCLUDE_DIR OR NOT FFTW3_LIBRARIES)
IF(NOT FFTW3_INCLUDE_DIR OR NOT FFTW3_LIBRARIES)
  MESSAGE(FATAL_ERROR "Could not find fftw3.")
ENDIF()

error message:

CMake Error at CMakeLists.txt:52 (MESSAGE):
  Could not find fftw3.

回答1:

You have the dynamic libraries installed, but do you have the "development" package installed? You probably need a file or symlink named something like:

libfftw3.so

You might need to install an fftw3-devel (or fftw3-dev) package.

Also, try removing the "lib" prefix and the .so.3 suffix:

FIND_LIBRARY(FFTW3_LIBRARIES NAMES fftw3 libfftw3)

If that doesn't work, try adding the PATHS argument:

FIND_LIBRARY(FFTW3_LIBRARIES NAMES fftw3 libfftw3 PATHS /usr/lib <other paths>)

Make sure the CMAKE_FIND_ROOT_PATH variable is set correctly (presumably you're not cross-compiling, so it's likely empty, and cmake will be using sensible locations for finding libraries).

See the cmake man page for detailed usage of the find_library function.

Lastly, look at this site for how to write a find_package script: http://www.cmake.org/Wiki/CMake:How_To_Find_Libraries



回答2:

I would normally expect to see symlinks like /usr/lib/libfftw.so -> libfftw.so.3. If those were in place, your find_library calls should work OK.

If you don't want to add symlinks, you can change your calls to:

find_library(FFTW3_LIBRARIES libfftw3.so.3 /usr/lib)
find_library(FFTW3F_LIBRARIES libfftw3f.so.3 /usr/lib)


回答3:

Try gui-cmake, http://www.cmake.org/cmake/help/runningcmake.html.

Then you can select the library needed manually.



标签: ubuntu cmake