Open heirecka opened 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.
What about a branch based on CMake version?
I tried cmake 3.10, and it worked.
I am on Gentoo with cmake 3.12.0 and it's failing...
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:
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.
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.
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?
Any news on this issue? What are the CMake recommendations on the topic?
Interested too, build failing with Cmake 3.12.4
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
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.
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.
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.
@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.
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
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.
still happening with cmake 3.22.1
but the hack above works
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/)