flann-lib / flann

Fast Library for Approximate Nearest Neighbors
http://people.cs.ubc.ca/~mariusm/flann
Other
2.25k stars 649 forks source link

Fails to build with cmake 3.11.0 #369

Open heirecka opened 6 years ago

heirecka commented 6 years ago

It errors out with that version because of 'add_library(flann_cpp SHARED "")'.

Possibly relevant from the changelog: "“add_library()” and “add_executable()” commands can now be called without any sources and will not complain as long as sources are added later via the “target_sources()” command." (https://blog.kitware.com/cmake-3-11-0-available-for-download/)

cmake -DCMAKE_COLOR_MAKEFILE:BOOL=TRUE -DCMAKE_VERBOSE_MAKEFILE:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=None -DCMAKE_C_FLAGS:STRING=-pipe -O2 -march=native -DCMAKE_CXX_FLAGS:STRING=-pipe -O2 -march=native -DCMAKE_AR:PATH=x86_64-pc-linux-gnu-ar -DCMAKE_RANLIB:PATH=x86_64-pc-linux-gnu-ranlib -DCMAKE_NM:PATH=x86_64-pc-linux-gnu-nm -DCMAKE_C_COMPILER:PATH=x86_64-pc-linux-gnu-cc -DCMAKE_CXX_COMPILER:PATH=x86_64-pc-linux-gnu-c++ -DCMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES:PATH=/usr/x86_64-pc-linux-gnu/include -DCMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES:PATH=/usr/x86_64-pc-linux-gnu/include -DCMAKE_INSTALL_PREFIX:PATH=/usr/x86_64-pc-linux-gnu -DCMAKE_FIND_ROOT_PATH=/usr/x86_64-pc-linux-gnu -DCMAKE_SYSTEM_PREFIX_PATH:PATH=/usr/x86_64-pc-linux-gnu -DCMAKE_INSTALL_LIBDIR:STRING=lib -DCMAKE_INSTALL_DATAROOTDIR:PATH=/usr/share/ -DBUILD_C_BINDINGS:BOOL=true -DBUILD_CUDA_LIB:BOOL=false -DBUILD_MATLAB_BINDINGS:BOOL=false -DBUILD_PYTHON_BINDINGS:BOOL=false -DDOCDIR=/usr/share/doc/flann-1.9.1 -DUSE_MPI:BOOL=false -DBUILD_DOC:BOOL=TRUE -DBUILD_EXAMPLES:BOOL=TRUE -DUSE_OPENMP:BOOL=FALSE -DBUILD_TESTS:BOOL=TRUE /var/tmp/paludis/build/sci-libs-flann-1.9.1/work/flann-1.9.1
-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.0
-- Check for working C compiler: /usr/x86_64-pc-linux-gnu/bin/x86_64-pc-linux-gnu-cc
-- Check for working C compiler: /usr/x86_64-pc-linux-gnu/bin/x86_64-pc-linux-gnu-cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/x86_64-pc-linux-gnu/bin/x86_64-pc-linux-gnu-c++
-- Check for working CXX compiler: /usr/x86_64-pc-linux-gnu/bin/x86_64-pc-linux-gnu-c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PythonInterp: /usr/x86_64-pc-linux-gnu/bin/python (found version "2.7.14") 
-- HDF5: Using hdf5 compiler wrapper to determine C configuration
-- Found HDF5: /usr/x86_64-pc-linux-gnu/lib/libhdf5.so;/usr/x86_64-pc-linux-gnu/lib/libz.so;/usr/x86_64-pc-linux-gnu/lib/libdl.so;/usr/x86_64-pc-linux-gnu/lib/libm.so (found version "1.10.1")  
-- Found GTest: /usr/x86_64-pc-linux-gnu/lib/libgtest.a  
-- Found LATEX: /usr/x86_64-pc-linux-gnu/bin/latex   
-- I could not find the latex2html command.
-- Install prefix: /usr/x86_64-pc-linux-gnu
-- Build type: None
-- Building C bindings: true
-- Building examples: TRUE
-- Building tests: TRUE
-- Building documentation: TRUE
-- Building python bindings: false
-- Building matlab bindings: false
-- Building CUDA library: false
-- Using OpenMP support: FALSE
-- Using MPI support: false
-- Configuring done
-- Build files have been written to: /var/tmp/paludis/build/sci-libs-flann-1.9.1/work/build
CMake Error at src/cpp/CMakeLists.txt:32 (add_library):
  No SOURCES given to target: flann_cpp

CMake Error at src/cpp/CMakeLists.txt:86 (add_library):
  No SOURCES given to target: flann
heirecka commented 6 years ago

FWIW, touch src/cpp/empty.cpp sed -e "/add_library(flann_cpp SHARED/ s/\"\"/empty.cpp/" -e "/add_library(flann SHARED/ s/\"\"/empty.cpp/" -i src/cpp/CMakeLists.txt

makes it build successfully.But it feels too hackish to turn it into a pull request.

jakirkham commented 6 years ago

What about a branch based on CMake version?

huixiangufl commented 6 years ago

I tried cmake 3.10, and it worked.

archenroot commented 6 years ago

I am on Gentoo with cmake 3.12.0 and it's failing...

archenroot commented 6 years ago

Its funny because there are some other packages failing with cmake <=3.10 and while I wanted to rebuild whole system because migration from GCC 6.4 to 7.3 I cannot make it on single run :dagger:

dreuter commented 6 years ago

I think the proper way to solve this would be to use add_library(flann_cpp INTERFACE).

More information can be found here: http://mariobadr.com/creating-a-header-only-library-with-cmake.html

I guess one problem might be, that this will not create a .so, so if you manually added -lflann_cpp you would get a linker error.

dreuter commented 6 years ago

I think the proper way to solve this would be to use add_library(flann_cpp INTERFACE).

More information can be found here: http://mariobadr.com/creating-a-header-only-library-with-cmake.html

I guess one problem might be, that this will not create a .so, so if you manually added -lflann_cpp you would get a linker error.

Ok, scrap that... After trying to apply this I saw, that the static library content is loaded into the shared library. That of course makes it impossible to use an INTERFACE library.

dreuter commented 6 years ago

In my opinion there are two ways to solve this.

Either revert 0fd62b43be2fbb0b8d791ee36290791224dc030c or add an empty flann_cpp.cpp and use it as source for the shared library.

Any preferences?

BotellaA commented 5 years ago

Any news on this issue? What are the CMake recommendations on the topic?

victorvianna commented 5 years ago

Interested too, build failing with Cmake 3.12.4

Flamefire commented 4 years ago

Any news on this issue? What are the CMake recommendations on the topic?

From a CMake heavy user: revert 0fd62b4. What is being done there is potentially problematic. Especially as FLANN_STATIC is defined. What does this mean now if the files compiled with the static define are used to create the shared library requring "hacking" the linker to make it work at all?

Yes it is faster but if you would want to do that, look into object libraries which are the cleaner approach. And is "faster" here really worth the trouble? There are maybe a dozen cpp files so save yourself the trouble and just build them twice and with the proper flags to avoid that leading to bugs in the future

tkircher commented 4 years ago

The solution that @heirecka posted works for me, though if you're building with CUDA (-DBUILD_CUDA_LIB=ON) you also have to include empty.cpp in the associated place (flann_cuda SHARED)

Like @Flamefire pointed out, the underlying problem is an incorrect use of CMake, so the solution is to fix the CMake scripts.

fidergo-stephane-gourichon commented 3 years ago

Still occurs on current master on Ubuntu 20.04

@heirecka 's answer did not work for me as is. I had to add backslashes to ensure lines after sed do make only one actual line, and adjust the double quotes into simple quotes because they really quote double quotes. Anyway, here it is with proper markup, so that you can just copy-paste into a shell:

touch src/cpp/empty.cpp
sed -e '/add_library(flann_cpp SHARED/ s/""/empty.cpp/' \
-e '/add_library(flann SHARED/ s/""/empty.cpp/' \
-i src/cpp/CMakeLists.txt

I still find this is hackish, yet that worked for me.

StefanBruens commented 2 years ago

When you look at the generated CMake targets file, you can see it is completely broken:

# Import target "flann::flann" for configuration "RelWithDebInfo"
set_property(TARGET flann::flann APPEND PROPERTY IMPORTED_CONFIGURATIONS RELWITHDEBINFO)
set_target_properties(flann::flann PROPERTIES
  IMPORTED_LINK_INTERFACE_LIBRARIES_RELWITHDEBINFO "-Wl,-whole-archive;flann::flann_s;-Wl,-no-whole-archive"
  IMPORTED_LOCATION_RELWITHDEBINFO "${_IMPORT_PREFIX}/lib64/libflann.so.1.9.2"
  IMPORTED_SONAME_RELWITHDEBINFO "libflann.so.1.9"
  )
...
# Import target "flann::flann_s" for configuration "RelWithDebInfo"
set_property(TARGET flann::flann_s APPEND PROPERTY IMPORTED_CONFIGURATIONS RELWITHDEBINFO)
set_target_properties(flann::flann_s PROPERTIES
  IMPORTED_LINK_INTERFACE_LANGUAGES_RELWITHDEBINFO "CXX"
  IMPORTED_LINK_INTERFACE_LIBRARIES_RELWITHDEBINFO "/usr/lib64/liblz4.so"
  IMPORTED_LOCATION_RELWITHDEBINFO "${_IMPORT_PREFIX}/lib64/libflann_s.a"
  )

The shared library should be self contained, any reference to the static library is wrong.

monajalal commented 1 year ago

@heirecka I tried your model and it didn't work. Do you have any suggestions for FLANN 1.9.1?

base) mona@ard-gpu-01:~/Downloads/flann-1.9.1$  touch src/cpp/empty.cpp
(base) mona@ard-gpu-01:~/Downloads/flann-1.9.1$ sed -e "/add_library(flann_cpp SHARED/ s/""/empty.cpp/" -e "/add_library(flann SHARED/ s/""/empty.cpp/" -i src/cpp/CMakeLists.txt
(base) mona@ard-gpu-01:~/Downloads/flann-1.9.1$ cd build/
(base) mona@ard-gpu-01:~/Downloads/flann-1.9.1/build$ cd ..
(base) mona@ard-gpu-01:~/Downloads/flann-1.9.1$ rm -rf build
(base) mona@ard-gpu-01:~/Downloads/flann-1.9.1$ mkdir build
(base) mona@ard-gpu-01:~/Downloads/flann-1.9.1$ cd build
(base) mona@ard-gpu-01:~/Downloads/flann-1.9.1/build$ cmake ..
CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 2.8.12 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.

-- The C compiler identification is GNU 11.3.0
-- The CXX compiler identification is GNU 11.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PythonInterp: /home/mona/anaconda3/bin/python (found version "3.9.13") 
-- Found HDF5: /usr/lib/x86_64-linux-gnu/hdf5/serial/libhdf5.so;/usr/lib/x86_64-linux-gnu/libcrypto.so;/usr/lib/x86_64-linux-gnu/libcurl.so;/usr/lib/x86_64-linux-gnu/libpthread.a;/usr/lib/x86_64-linux-gnu/libsz.so;/usr/lib/x86_64-linux-gnu/libz.so;/usr/lib/x86_64-linux-gnu/libdl.a;/usr/lib/x86_64-linux-gnu/libm.so (found version "1.10.7")  
-- Could NOT find GTest (missing: GTEST_LIBRARY GTEST_INCLUDE_DIR GTEST_MAIN_LIBRARY) 
CMake Warning at CMakeLists.txt:117 (message):
  gtest library not found, some tests will not be run

-- Found OpenMP_C: -fopenmp (found version "4.5") 
-- Found OpenMP_CXX: -fopenmp (found version "4.5") 
-- Found OpenMP: TRUE (found version "4.5")  
CMake Error at src/cpp/CMakeLists.txt:32:
  Parse error.  Expected a command name, got unquoted argument with text
  "empty.cpp".

-- Configuring incomplete, errors occurred!
See also "/home/mona/Downloads/flann-1.9.1/build/CMakeFiles/CMakeOutput.log".

Before that I was getting this error:

(base) mona@ard-gpu-01:~/Downloads/flann-1.9.1$ mkdir build
(base) mona@ard-gpu-01:~/Downloads/flann-1.9.1$ vi README.md 
(base) mona@ard-gpu-01:~/Downloads/flann-1.9.1$ cd build/
(base) mona@ard-gpu-01:~/Downloads/flann-1.9.1/build$ cmake ..
CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 2.8.12 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.

-- The C compiler identification is GNU 11.3.0
-- The CXX compiler identification is GNU 11.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PythonInterp: /home/mona/anaconda3/bin/python (found version "3.9.13") 
-- Found HDF5: /usr/lib/x86_64-linux-gnu/hdf5/serial/libhdf5.so;/usr/lib/x86_64-linux-gnu/libcrypto.so;/usr/lib/x86_64-linux-gnu/libcurl.so;/usr/lib/x86_64-linux-gnu/libpthread.a;/usr/lib/x86_64-linux-gnu/libsz.so;/usr/lib/x86_64-linux-gnu/libz.so;/usr/lib/x86_64-linux-gnu/libdl.a;/usr/lib/x86_64-linux-gnu/libm.so (found version "1.10.7")  
-- Could NOT find GTest (missing: GTEST_LIBRARY GTEST_INCLUDE_DIR GTEST_MAIN_LIBRARY) 
CMake Warning at CMakeLists.txt:117 (message):
  gtest library not found, some tests will not be run

-- Found OpenMP_C: -fopenmp (found version "4.5") 
-- Found OpenMP_CXX: -fopenmp (found version "4.5") 
-- Found OpenMP: TRUE (found version "4.5")  
CMake Warning (dev) at src/matlab/CMakeLists.txt:19 (get_property):
  Policy CMP0026 is not set: Disallow use of the LOCATION target property.
  Run "cmake --help-policy CMP0026" for policy details.  Use the cmake_policy
  command to set the policy and suppress this warning.

  The LOCATION property should not be read from target "flann_s".  Use the
  target name directly with add_custom_command, or use the generator
  expression $<TARGET_FILE>, as appropriate.

This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning at src/matlab/CMakeLists.txt:87 (message):
  Cannot find MATLAB or Octave instalation.  Make sure that the 'bin'
  directory from the MATLAB instalation or that mkoctfile is in PATH

-- Could NOT find LATEX (missing: LATEX_COMPILER) 
-- Install prefix: /usr/local
-- Build type: RelWithDebInfo
-- Building C bindings: ON
-- Building examples: ON
-- Building tests: ON
-- Building documentation: ON
-- Building python bindings: ON
-- Building matlab bindings: ON
-- Building CUDA library: OFF
-- Using OpenMP support: ON
-- Using MPI support: OFF
-- Configuring done
CMake Error at src/cpp/CMakeLists.txt:32 (add_library):
  No SOURCES given to target: flann_cpp

CMake Error at src/cpp/CMakeLists.txt:86 (add_library):
  No SOURCES given to target: flann

CMake Generate step failed.  Build files cannot be regenerated correctly.
monajalal commented 1 year ago

confirming that @fidergo-stephane-gourichon 's method worked for me. Thanks a lot

(base) mona@ard-gpu-01:~/Downloads/flann-1.9.1$ touch src/cpp/empty.cpp
(base) mona@ard-gpu-01:~/Downloads/flann-1.9.1$ sed -e '/add_library(flann_cpp SHARED/ s/""/empty.cpp/' \
-e '/add_library(flann SHARED/ s/""/empty.cpp/' \
-i src/cpp/CMakeLists.txt
(base) mona@ard-gpu-01:~/Downloads/flann-1.9.1$ mkdir build
(base) mona@ard-gpu-01:~/Downloads/flann-1.9.1$ cd build
(base) mona@ard-gpu-01:~/Downloads/flann-1.9.1/build$ cmake ..
CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 2.8.12 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.

-- The C compiler identification is GNU 11.3.0
-- The CXX compiler identification is GNU 11.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PythonInterp: /home/mona/anaconda3/bin/python (found version "3.9.13") 
-- Found HDF5: /usr/lib/x86_64-linux-gnu/hdf5/serial/libhdf5.so;/usr/lib/x86_64-linux-gnu/libcrypto.so;/usr/lib/x86_64-linux-gnu/libcurl.so;/usr/lib/x86_64-linux-gnu/libpthread.a;/usr/lib/x86_64-linux-gnu/libsz.so;/usr/lib/x86_64-linux-gnu/libz.so;/usr/lib/x86_64-linux-gnu/libdl.a;/usr/lib/x86_64-linux-gnu/libm.so (found version "1.10.7")  
-- Could NOT find GTest (missing: GTEST_LIBRARY GTEST_INCLUDE_DIR GTEST_MAIN_LIBRARY) 
CMake Warning at CMakeLists.txt:117 (message):
  gtest library not found, some tests will not be run

-- Found OpenMP_C: -fopenmp (found version "4.5") 
-- Found OpenMP_CXX: -fopenmp (found version "4.5") 
-- Found OpenMP: TRUE (found version "4.5")  
CMake Warning (dev) at src/matlab/CMakeLists.txt:19 (get_property):
  Policy CMP0026 is not set: Disallow use of the LOCATION target property.
  Run "cmake --help-policy CMP0026" for policy details.  Use the cmake_policy
  command to set the policy and suppress this warning.

  The LOCATION property should not be read from target "flann_s".  Use the
  target name directly with add_custom_command, or use the generator
  expression $<TARGET_FILE>, as appropriate.

This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning at src/matlab/CMakeLists.txt:87 (message):
  Cannot find MATLAB or Octave instalation.  Make sure that the 'bin'
  directory from the MATLAB instalation or that mkoctfile is in PATH

-- Could NOT find LATEX (missing: LATEX_COMPILER) 
-- Install prefix: /usr/local
-- Build type: RelWithDebInfo
-- Building C bindings: ON
-- Building examples: ON
-- Building tests: ON
-- Building documentation: ON
-- Building python bindings: ON
-- Building matlab bindings: ON
-- Building CUDA library: OFF
-- Using OpenMP support: ON
-- Using MPI support: OFF
-- Configuring done
-- Generating done
-- Build files have been written to: /home/mona/Downloads/flann-1.9.1/build
StefanBruens commented 1 year ago

CMake Error at src/cpp/CMakeLists.txt:86 (add_library): No SOURCES given to target: flann

https://cmake.org/cmake/help/v3.11/release/3.11.html#commands add_library without SOURCES requires CMake 3.11.

sebastianserna30 commented 4 months ago

still happening with cmake 3.22.1

but the hack above works