-
Notifications
You must be signed in to change notification settings - Fork 647
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fails to build with cmake 3.11.0 #369
Comments
FWIW, makes it build successfully.But it feels too hackish to turn it into a pull request. |
CMake < 3.11 doesn't support add_library() without any source file (i.e add_library(foo SHARED)). But flann CMake use a trick that use an empty string "" as source list (i.e add_library(foo SHARED "")). This look like a bug in CMake < 3.11. With CMake >= 3.11, the new behaviour of add_library() break the existing flann CMake code. >From CMake Changelog [1]: "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." Note: flann CMake code doesn't use target_sources() since no source file are provided intentionally since the flann shared library is created by linking with the flann_cpp_s static library with this line: target_link_libraries(flann_cpp -Wl,-whole-archive flann_cpp_s -Wl,-no-whole-archive) If you try to use "add_library(flann_cpp SHARED ${CPP_SOURCES})" (as it should be normally done), the link fail due to already defined symbol. They are building the shared version using the static library "to speedup the build time" [3] This issue is already reported upstream [2] with a proposed solution. Fixes: http://autobuild.buildroot.net/results/b2f/b2febfaf8c44ce477b3e4a5b9b976fd25e8d7454 [1] https://cmake.org/cmake/help/v3.11/release/3.11.html [2] flann-lib/flann#369 [3] flann-lib/flann@0fd62b4 Signed-off-by: Romain Naour <romain.naour@gmail.com> Cc: Davide Viti <zinosat@tiscali.it> Cc: Bernd Kuhls <bernd.kuhls@t-online.de> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
What about a branch based on CMake version? |
I tried cmake 3.10, and it worked. |
CMake < 3.11 doesn't support add_library() without any source file (i.e add_library(foo SHARED)). But flann CMake use a trick that use an empty string "" as source list (i.e add_library(foo SHARED "")). This look like a bug in CMake < 3.11. With CMake >= 3.11, the new behaviour of add_library() break the existing flann CMake code. >From CMake Changelog [1]: "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." Note: flann CMake code doesn't use target_sources() since no source file are provided intentionally since the flann shared library is created by linking with the flann_cpp_s static library with this line: target_link_libraries(flann_cpp -Wl,-whole-archive flann_cpp_s -Wl,-no-whole-archive) If you try to use "add_library(flann_cpp SHARED ${CPP_SOURCES})" (as it should be normally done), the link fail due to already defined symbol. They are building the shared version using the static library "to speedup the build time" [3] This issue is already reported upstream [2] with a proposed solution. Fixes: http://autobuild.buildroot.net/results/b2f/b2febfaf8c44ce477b3e4a5b9b976fd25e8d7454 [1] https://cmake.org/cmake/help/v3.11/release/3.11.html [2] flann-lib/flann#369 [3] flann-lib/flann@0fd62b4 Signed-off-by: Romain Naour <romain.naour@gmail.com> Cc: Davide Viti <zinosat@tiscali.it> Cc: Bernd Kuhls <bernd.kuhls@t-online.de> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com> (cherry picked from commit 0c46947) Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
CMake < 3.11 doesn't support add_library() without any source file (i.e add_library(foo SHARED)). But flann CMake use a trick that use an empty string "" as source list (i.e add_library(foo SHARED "")). This look like a bug in CMake < 3.11. With CMake >= 3.11, the new behaviour of add_library() break the existing flann CMake code. >From CMake Changelog [1]: "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." Note: flann CMake code doesn't use target_sources() since no source file are provided intentionally since the flann shared library is created by linking with the flann_cpp_s static library with this line: target_link_libraries(flann_cpp -Wl,-whole-archive flann_cpp_s -Wl,-no-whole-archive) If you try to use "add_library(flann_cpp SHARED ${CPP_SOURCES})" (as it should be normally done), the link fail due to already defined symbol. They are building the shared version using the static library "to speedup the build time" [3] This issue is already reported upstream [2] with a proposed solution. Fixes: http://autobuild.buildroot.net/results/b2f/b2febfaf8c44ce477b3e4a5b9b976fd25e8d7454 [1] https://cmake.org/cmake/help/v3.11/release/3.11.html [2] flann-lib/flann#369 [3] flann-lib/flann@0fd62b4 Signed-off-by: Romain Naour <romain.naour@gmail.com> Cc: Davide Viti <zinosat@tiscali.it> Cc: Bernd Kuhls <bernd.kuhls@t-online.de> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
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 🗡️ |
|
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 |
In my opinion there are two ways to solve this. Either revert 0fd62b4 or add an empty Any preferences? |
Any news on this issue? What are the CMake recommendations on the topic? |
Interested too, build failing with Cmake 3.12.4 |
Closes flann-lib#369
Closes flann-lib#369
From a CMake heavy user: revert 0fd62b4. What is being done there is potentially problematic. Especially as 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. 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. |
See issue 369 on github: flann-lib/flann#369
When you look at the generated CMake targets file, you can see it is completely broken:
The shared library should be self contained, any reference to the static library is wrong. |
Build the shared library on Linux the same way as on Windows, i.e. compile the sources individually for static and shared libs. This removes the "FLANN_STATIC" compile definition from the shared library build (confusing, albeit without any effect on Linux), and avoids any linker trickery. Also allow to disable build and installation of the static libraries completely, as these are often unwanted on Linux distributions. Fixes flann-lib#498. See flann-lib#369.
@heirecka
Before that I was getting this error:
|
confirming that @fidergo-stephane-gourichon 's method worked for me. Thanks a lot
|
https://cmake.org/cmake/help/v3.11/release/3.11.html#commands |
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/)
The text was updated successfully, but these errors were encountered: