Building FLANN with Cmake fails - cmake

I am trying to build FLANN libraries in order to build PCL library afterwards.
I get an error while using CMake to compile the source.
I guess I am missing something very basic. Since I can't find a compiled library for my system I have to build it myself.
With the command
~/flann-1.8.4-src/build> cmake ..
I get
CMake Error at src/cpp/CMakeLists.txt:86 (add_library):
No SOURCES given to target: flann
CMake Error at src/cpp/CMakeLists.txt:32 (add_library):
No SOURCES given to target: flann_cpp
This happens with flann 1.8.4 and 1.9.1 on a SLES11 operating system.
Any hint?
Here a complete transcription of what cmake says:
-- Could NOT find HDF5 (missing: HDF5_LIBRARIES HDF5_INCLUDE_DIRS) (found version "")
CMake Warning at CMakeLists.txt:76 (message):
hdf5 library not found, some tests will not be run
-- Could NOT find GTest (missing: GTEST_LIBRARY GTEST_INCLUDE_DIR GTEST_MAIN_LIBRARY)
CMake Warning at CMakeLists.txt:115 (message):
gtest library not found, some tests will not be run
-- Found OpenMP_C: -fopenmp
-- Found OpenMP_CXX: -fopenmp
-- Found OpenMP: TRUE
CMake Warning at src/matlab/CMakeLists.txt:79 (message):
Cannot find MATLAB or Octave instalation. Make sure that the 'bin'
directory from the MATLAB instalation or that mkoctfile is in PATH
hdf5 library not found, not compiling flann_example.cpp
-- Could NOT find LATEX (missing: LATEX_COMPILER)
-- Install prefix: /usr/local
-- Build type: RelWithDebInfo
-- Building C bindings: 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:86 (add_library):
No SOURCES given to target: flann
CMake Error at src/cpp/CMakeLists.txt:32 (add_library):
No SOURCES given to target: flann_cpp
-- Build files have been written to: ~/flann-1.8.4-src/build

In your flann dir
run
touch src/cpp/empty.cpp
In src/cpp/CMakeLists.txt
replace
add_library(flann_cpp SHARED "") and add_library(flann SHARED "")
with
add_library(flann_cpp SHARED empty.cpp) and add_library(flann SHARED empty.cpp)
Hope this helps :)
link, thanks to the comment by Tsyvarev

Related

cmake targets from find_package are not propagated to siblings [duplicate]

I have a set of libraries and their respective tests, and they are organized in the following fashion:
-Lib1
-Lib1_Test
-Lib2
-Lib2_Test
-Lib3
-Lib3_Test
....
and so on. some of these libs depend on others, for example Lib1 depends on Lib2, and Lib3 depends on Lib1. I can easily build each target separately and all is fine. However, When I try to build them in such a way that each target first builds its dependencies and then itself I face an issue here.
For this very purpose, I used 'add_subdirectory` for each dependenant target and I also check if the target is already built or not so only if its not, we include it and build it.
This is how one of my CMakeLists.txt look like :
cmake_minimum_required(VERSION 3.11)
project(FV)
set(CMAKE_CXX_STANDARD 17)
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC" )
find_package(Torch REQUIRED)
find_package(OpenCV REQUIRED)
find_package(Protobuf REQUIRED)
if ("${TORCH_LIB_DIRS}" STREQUAL "")
set(TORCH_LIB_DIRS /home/rika/libtorch-cxx11-abi-shared-with-deps-1.6.0+cpu/libtorch/lib)
endif()
get_filename_component(PARENT_DIR ${PROJECT_SOURCE_DIR} DIRECTORY)
#if (DLL)
add_definitions(-D_FV_BUILD_DLL)
set(CMAKE_INSTALL_PREFIX ${PARENT_DIR}/built_stuff)
if(NOT TARGET AntiSpoofer)
add_subdirectory(${PARENT_DIR}/AntiSpoofer ${PARENT_DIR}/AntiSpoofer/build)
endif()
if(NOT TARGET Detector)
add_subdirectory(${PARENT_DIR}/Detector ${PARENT_DIR}/Detector/build)
endif()
if(NOT TARGET Hashing)
add_subdirectory(${PARENT_DIR}/Hashing ${PARENT_DIR}/Hashing/build)
endif()
include_directories(${PARENT_DIR}/Dependencies/include ${Protobuf_INCLUDE_DIRS} ${TORCH_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS})
set(FV_H ${PARENT_DIR}/Dependencies/include/FV/FV.h)
set(Config_H ${PARENT_DIR}/Dependencies/include/messages/Config.pb.h)
set(TorchSerializer_H ${PARENT_DIR}/Dependencies/include/messages/TorchSerializer.pb.h)
set(TorchSerializer_PY ${PARENT_DIR}/Dependencies/include/messages/TorchSerializer_pb2.py)
set(FV_SRC ./FV.cpp)
set(Config_SRC ${PARENT_DIR}/Dependencies/include/messages/Config.pb.cc)
set(TorchSerializer_SRC ${PARENT_DIR}/Dependencies/include/messages/TorchSerializer.pb.cc)
LINK_DIRECTORIES(${TORCH_LIB_DIRS})
LINK_DIRECTORIES(${PARENT_DIR}/AntiSpoofer/build)
LINK_DIRECTORIES(${PARENT_DIR}/Blinker/build)
LINK_DIRECTORIES(${PARENT_DIR}/Detector/build)
LINK_DIRECTORIES(${PARENT_DIR}/Hashing/build)
add_library(
FV
SHARED
${FV_SRC}
${Config_SRC}
${TorchSerializer_SRC}
)
target_link_directories(FV PUBLIC ${PARENT_DIR}/built_stuff/lib)
# Link
target_link_libraries(FV ${OpenCV_LIBS})
target_link_libraries(FV ${TORCH_LIB_DIRS}/libc10.so)
target_link_libraries(FV ${TORCH_LIB_DIRS}/libtorch_cpu.so)
target_link_libraries(FV Hashing)
target_link_libraries(FV Blinker)
target_link_libraries(FV AntiSpoofer)
target_link_libraries(FV Detector)
# add FV include
install(TARGETS FV LIBRARY DESTINATION lib)
install(FILES ${FV_H} DESTINATION include/FV)
# add protobuf related headers/srcs for c++ and python
install(FILES ${Config_H} DESTINATION include/messages)
install(FILES ${TorchSerializer_H} DESTINATION include/messages)
install(FILES ${Config_SRC} DESTINATION src/messages)
install(FILES ${TorchSerializer_SRC} DESTINATION src/messages)
install(FILES ${TorchSerializer_PY} DESTINATION Python)
when I try to call this very cmakelists like this :
cmake -DCMAKE_PREFIX_PATH="/home/rika/libtorch-cxx11-abi-shared-with-deps-1.6.0+cpu/libtorch/share/cmake" ..
everything builds just fine and all targets seem to be able to get and use the passed CMAKE_PREFIX_PATH that I send here. However, just after this, if I cd into the FV_Test which by the way is given below, it fails with the error messages indicating the failure of CMake in finding torch! which is clearly specified in the argument when calling CMake. This is the error message I get after trying to build FV_Test:
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.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 OpenCV: /usr/local (found version "3.4.10")
-- Found Protobuf: /usr/local/lib/libprotobuf.so;-lpthread (found version "3.13.0")
-- Found Threads: TRUE
-- Found Torch: /home/rika/libtorch-cxx11-abi-shared-with-deps-1.6.0+cpu/libtorch/lib/libtorch.so
-- Using CMake version: 3.18.2
-- Compiling dlib version: 19.21.0
-- Found X11: /usr/include
-- Looking for XOpenDisplay in /usr/lib/x86_64-linux-gnu/libX11.so;/usr/lib/x86_64-linux-gnu/libXext.so
-- Looking for XOpenDisplay in /usr/lib/x86_64-linux-gnu/libX11.so;/usr/lib/x86_64-linux-gnu/libXext.so - found
-- Looking for gethostbyname
-- Looking for gethostbyname - found
-- Looking for connect
-- Looking for connect - found
-- Looking for remove
-- Looking for remove - found
-- Looking for shmat
-- Looking for shmat - found
-- Looking for IceConnectionNumber in ICE
-- Looking for IceConnectionNumber in ICE - found
-- Found system copy of libpng: /usr/lib/x86_64-linux-gnu/libpng.so;/usr/lib/x86_64-linux-gnu/libz.so
-- Found system copy of libjpeg: /usr/lib/x86_64-linux-gnu/libjpeg.so
-- Searching for BLAS and LAPACK
-- Searching for BLAS and LAPACK
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1")
-- Checking for module 'cblas'
-- No package 'cblas' found
-- Checking for module 'lapack'
-- Found lapack, version 3.10.3
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of void*
-- Check size of void* - done
-- Found Intel MKL BLAS/LAPACK library
-- Looking for sgesv
-- Looking for sgesv - found
-- Looking for sgesv_
-- Looking for sgesv_ - found
CUDA_TOOLKIT_ROOT_DIR not found or specified
-- Could NOT find CUDA (missing: CUDA_TOOLKIT_ROOT_DIR CUDA_NVCC_EXECUTABLE CUDA_INCLUDE_DIRS CUDA_CUDART_LIBRARY) (Required is at least version "7.5")
-- DID NOT FIND CUDA
-- Disabling CUDA support for dlib. DLIB WILL NOT USE CUDA
-- C++11 activated.
-- Configuring done
CMake Error at CMakeLists.txt:58 (target_link_libraries):
Error evaluating generator expression:
$<TARGET_PROPERTY:torch_cpu,INTERFACE_COMPILE_DEFINITIONS>
Target "torch_cpu" not found.
CMake Error at CMakeLists.txt:58 (target_link_libraries):
Error evaluating generator expression:
$<TARGET_PROPERTY:torch,INTERFACE_COMPILE_DEFINITIONS>
Target "torch" not found.
CMake Error at CMakeLists.txt:58 (target_link_libraries):
Error evaluating generator expression:
$<TARGET_PROPERTY:torch_cpu,INTERFACE_INCLUDE_DIRECTORIES>
Target "torch_cpu" not found.
CMake Error at CMakeLists.txt:58 (target_link_libraries):
Error evaluating generator expression:
$<TARGET_PROPERTY:torch,INTERFACE_INCLUDE_DIRECTORIES>
Target "torch" not found.
CMake Error:
Error evaluating generator expression:
$<TARGET_PROPERTY:torch_cpu,INTERFACE_SYSTEM_INCLUDE_DIRECTORIES>
Target "torch_cpu" not found.
CMake Error:
Error evaluating generator expression:
$<TARGET_PROPERTY:torch_cpu,INTERFACE_INCLUDE_DIRECTORIES>
Target "torch_cpu" not found.
CMake Error:
Error evaluating generator expression:
$<TARGET_PROPERTY:torch,INTERFACE_SYSTEM_INCLUDE_DIRECTORIES>
Target "torch" not found.
CMake Error:
Error evaluating generator expression:
$<TARGET_PROPERTY:torch,INTERFACE_INCLUDE_DIRECTORIES>
Target "torch" not found.
CMake Error at CMakeLists.txt:58 (target_link_libraries):
Error evaluating generator expression:
$<TARGET_PROPERTY:torch_cpu,INTERFACE_COMPILE_OPTIONS>
Target "torch_cpu" not found.
CMake Error at CMakeLists.txt:58 (target_link_libraries):
Error evaluating generator expression:
$<TARGET_PROPERTY:torch,INTERFACE_COMPILE_OPTIONS>
Target "torch" not found.
CMake Warning at CMakeLists.txt:49 (add_executable):
Cannot generate a safe runtime search path for target FV_test because files
in some directories may conflict with libraries in implicit directories:
runtime library [libpng16.so.16] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/home/rika/anaconda3/lib
runtime library [libz.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/home/rika/anaconda3/lib
Some of these libraries may not be found correctly.
CMake Error at CMakeLists.txt:58 (target_link_libraries):
Error evaluating generator expression:
$<TARGET_PROPERTY:torch_cpu,INTERFACE_COMPILE_DEFINITIONS>
Target "torch_cpu" not found.
CMake Error at CMakeLists.txt:58 (target_link_libraries):
Error evaluating generator expression:
$<TARGET_PROPERTY:torch,INTERFACE_COMPILE_DEFINITIONS>
Target "torch" not found.
CMake Error at CMakeLists.txt:58 (target_link_libraries):
Error evaluating generator expression:
$<TARGET_PROPERTY:torch_cpu,INTERFACE_INCLUDE_DIRECTORIES>
Target "torch_cpu" not found.
CMake Error at CMakeLists.txt:58 (target_link_libraries):
Error evaluating generator expression:
$<TARGET_PROPERTY:torch,INTERFACE_INCLUDE_DIRECTORIES>
Target "torch" not found.
CMake Warning at /home/rika/Desktop/LibtorchPort/FV/CMakeLists.txt:68 (add_library):
Cannot generate a safe runtime search path for target FV because files in
some directories may conflict with libraries in implicit directories:
runtime library [libpng16.so.16] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/home/rika/anaconda3/lib
runtime library [libz.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/home/rika/anaconda3/lib
Some of these libraries may not be found correctly.
CMake Warning at /home/rika/Desktop/LibtorchPort/AntiSpoofer/CMakeLists.txt:57 (add_library):
Cannot generate a safe runtime search path for target AntiSpoofer because
files in some directories may conflict with libraries in implicit
directories:
runtime library [libpng16.so.16] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/home/rika/anaconda3/lib
runtime library [libz.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/home/rika/anaconda3/lib
Some of these libraries may not be found correctly.
CMake Warning at /home/rika/Desktop/LibtorchPort/Blinker/CMakeLists.txt:46 (add_library):
Cannot generate a safe runtime search path for target Blinker because files
in some directories may conflict with libraries in implicit directories:
runtime library [libpng16.so.16] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/home/rika/anaconda3/lib
runtime library [libz.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/home/rika/anaconda3/lib
Some of these libraries may not be found correctly.
-- Generating done
CMake Generate step failed. Build files cannot be regenerated correctly.
And this is the CMakeLists.txt that I'm using for FV_Test.
cmake_minimum_required(VERSION 3.11)
project(FV_Test)
set(CMAKE_CXX_STANDARD 17)
find_package(OpenCV REQUIRED)
find_package(Protobuf REQUIRED)
if ("${TORCH_LIB_DIRS}" STREQUAL "")
set(TORCH_LIB_DIRS /home/rika/libtorch-cxx11-abi-shared-with-deps-1.6.0+cpu/libtorch/lib)
endif()
get_filename_component(PARENT_DIR ${PROJECT_SOURCE_DIR} DIRECTORY)
if(NOT TARGET FV)
add_subdirectory(${PARENT_DIR}/FV ${PARENT_DIR}/FV/build)
endif()
set(CMAKE_INSTALL_PREFIX ${PARENT_DIR}/built_stuff)
include_directories(${PARENT_DIR}/Dependencies/include ${OpenCV_INCLUDE_DIRS} ${Protobuf_INCLUDE_DIRS}) #
LINK_DIRECTORIES(${TORCH_LIB_DIRS})
LINK_DIRECTORIES(${PARENT_DIR}/AntiSpoofer/build)
LINK_DIRECTORIES(${PARENT_DIR}/Blinker/build)
LINK_DIRECTORIES(${PARENT_DIR}/FV/build)
add_executable(FV_test ./FV_Test.cpp )
target_link_directories(FV_test PUBLIC ${PARENT_DIR}/AntiSpoofer/build)
target_link_directories(FV_test PUBLIC ${PARENT_DIR}/Blinker/build)
target_link_directories(FV_test PUBLIC ${PARENT_DIR}/FV/build)
# Link
target_link_libraries(FV_test ${OpenCV_LIBS})
target_link_libraries(FV_test ${Protobuf_LIBRARIES})
target_link_libraries(FV_test FV)
target_link_libraries(FV_test Blinker)
install(TARGETS FV_test DESTINATION bin)
Why am I seeing this behavior and how can I solve this?
If the problem is really depicted in the following comment:
As far as I understand, the core of the problem is: 1. In subdirectory use find_package(Torch REQUIRED) and then link some library with a Torch library via target_link_libraries(mylib ${TORCH_LIBRARIES}). 2. Linking with that library in the outer directory: target_link_libraries(myexe mylib). For some (unknown) reason, during the last link CMake tries to evaluate generator expressions for torch_cpu. But this is an IMPORTED target, which is created in the subdirectory, so it cannot be accessed from the outer directory. – Tsyvarev Sep 27 '20 at 8:15
I ran into the same problem with Pytorch. The fix that worked for me was to link the torch libraries privately: target_link_libraries(mylib PRIVATE ${TORCH_LIBRARIES}").
Now don't ask my why that works I wouldn't be able to answer that.

CMake cant find the external libraries when subdirectory is used to build dependencies for each target

I have a set of libraries and their respective tests, and they are organized in the following fashion:
-Lib1
-Lib1_Test
-Lib2
-Lib2_Test
-Lib3
-Lib3_Test
....
and so on. some of these libs depend on others, for example Lib1 depends on Lib2, and Lib3 depends on Lib1. I can easily build each target separately and all is fine. However, When I try to build them in such a way that each target first builds its dependencies and then itself I face an issue here.
For this very purpose, I used 'add_subdirectory` for each dependenant target and I also check if the target is already built or not so only if its not, we include it and build it.
This is how one of my CMakeLists.txt look like :
cmake_minimum_required(VERSION 3.11)
project(FV)
set(CMAKE_CXX_STANDARD 17)
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC" )
find_package(Torch REQUIRED)
find_package(OpenCV REQUIRED)
find_package(Protobuf REQUIRED)
if ("${TORCH_LIB_DIRS}" STREQUAL "")
set(TORCH_LIB_DIRS /home/rika/libtorch-cxx11-abi-shared-with-deps-1.6.0+cpu/libtorch/lib)
endif()
get_filename_component(PARENT_DIR ${PROJECT_SOURCE_DIR} DIRECTORY)
#if (DLL)
add_definitions(-D_FV_BUILD_DLL)
set(CMAKE_INSTALL_PREFIX ${PARENT_DIR}/built_stuff)
if(NOT TARGET AntiSpoofer)
add_subdirectory(${PARENT_DIR}/AntiSpoofer ${PARENT_DIR}/AntiSpoofer/build)
endif()
if(NOT TARGET Detector)
add_subdirectory(${PARENT_DIR}/Detector ${PARENT_DIR}/Detector/build)
endif()
if(NOT TARGET Hashing)
add_subdirectory(${PARENT_DIR}/Hashing ${PARENT_DIR}/Hashing/build)
endif()
include_directories(${PARENT_DIR}/Dependencies/include ${Protobuf_INCLUDE_DIRS} ${TORCH_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS})
set(FV_H ${PARENT_DIR}/Dependencies/include/FV/FV.h)
set(Config_H ${PARENT_DIR}/Dependencies/include/messages/Config.pb.h)
set(TorchSerializer_H ${PARENT_DIR}/Dependencies/include/messages/TorchSerializer.pb.h)
set(TorchSerializer_PY ${PARENT_DIR}/Dependencies/include/messages/TorchSerializer_pb2.py)
set(FV_SRC ./FV.cpp)
set(Config_SRC ${PARENT_DIR}/Dependencies/include/messages/Config.pb.cc)
set(TorchSerializer_SRC ${PARENT_DIR}/Dependencies/include/messages/TorchSerializer.pb.cc)
LINK_DIRECTORIES(${TORCH_LIB_DIRS})
LINK_DIRECTORIES(${PARENT_DIR}/AntiSpoofer/build)
LINK_DIRECTORIES(${PARENT_DIR}/Blinker/build)
LINK_DIRECTORIES(${PARENT_DIR}/Detector/build)
LINK_DIRECTORIES(${PARENT_DIR}/Hashing/build)
add_library(
FV
SHARED
${FV_SRC}
${Config_SRC}
${TorchSerializer_SRC}
)
target_link_directories(FV PUBLIC ${PARENT_DIR}/built_stuff/lib)
# Link
target_link_libraries(FV ${OpenCV_LIBS})
target_link_libraries(FV ${TORCH_LIB_DIRS}/libc10.so)
target_link_libraries(FV ${TORCH_LIB_DIRS}/libtorch_cpu.so)
target_link_libraries(FV Hashing)
target_link_libraries(FV Blinker)
target_link_libraries(FV AntiSpoofer)
target_link_libraries(FV Detector)
# add FV include
install(TARGETS FV LIBRARY DESTINATION lib)
install(FILES ${FV_H} DESTINATION include/FV)
# add protobuf related headers/srcs for c++ and python
install(FILES ${Config_H} DESTINATION include/messages)
install(FILES ${TorchSerializer_H} DESTINATION include/messages)
install(FILES ${Config_SRC} DESTINATION src/messages)
install(FILES ${TorchSerializer_SRC} DESTINATION src/messages)
install(FILES ${TorchSerializer_PY} DESTINATION Python)
when I try to call this very cmakelists like this :
cmake -DCMAKE_PREFIX_PATH="/home/rika/libtorch-cxx11-abi-shared-with-deps-1.6.0+cpu/libtorch/share/cmake" ..
everything builds just fine and all targets seem to be able to get and use the passed CMAKE_PREFIX_PATH that I send here. However, just after this, if I cd into the FV_Test which by the way is given below, it fails with the error messages indicating the failure of CMake in finding torch! which is clearly specified in the argument when calling CMake. This is the error message I get after trying to build FV_Test:
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.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 OpenCV: /usr/local (found version "3.4.10")
-- Found Protobuf: /usr/local/lib/libprotobuf.so;-lpthread (found version "3.13.0")
-- Found Threads: TRUE
-- Found Torch: /home/rika/libtorch-cxx11-abi-shared-with-deps-1.6.0+cpu/libtorch/lib/libtorch.so
-- Using CMake version: 3.18.2
-- Compiling dlib version: 19.21.0
-- Found X11: /usr/include
-- Looking for XOpenDisplay in /usr/lib/x86_64-linux-gnu/libX11.so;/usr/lib/x86_64-linux-gnu/libXext.so
-- Looking for XOpenDisplay in /usr/lib/x86_64-linux-gnu/libX11.so;/usr/lib/x86_64-linux-gnu/libXext.so - found
-- Looking for gethostbyname
-- Looking for gethostbyname - found
-- Looking for connect
-- Looking for connect - found
-- Looking for remove
-- Looking for remove - found
-- Looking for shmat
-- Looking for shmat - found
-- Looking for IceConnectionNumber in ICE
-- Looking for IceConnectionNumber in ICE - found
-- Found system copy of libpng: /usr/lib/x86_64-linux-gnu/libpng.so;/usr/lib/x86_64-linux-gnu/libz.so
-- Found system copy of libjpeg: /usr/lib/x86_64-linux-gnu/libjpeg.so
-- Searching for BLAS and LAPACK
-- Searching for BLAS and LAPACK
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1")
-- Checking for module 'cblas'
-- No package 'cblas' found
-- Checking for module 'lapack'
-- Found lapack, version 3.10.3
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of void*
-- Check size of void* - done
-- Found Intel MKL BLAS/LAPACK library
-- Looking for sgesv
-- Looking for sgesv - found
-- Looking for sgesv_
-- Looking for sgesv_ - found
CUDA_TOOLKIT_ROOT_DIR not found or specified
-- Could NOT find CUDA (missing: CUDA_TOOLKIT_ROOT_DIR CUDA_NVCC_EXECUTABLE CUDA_INCLUDE_DIRS CUDA_CUDART_LIBRARY) (Required is at least version "7.5")
-- DID NOT FIND CUDA
-- Disabling CUDA support for dlib. DLIB WILL NOT USE CUDA
-- C++11 activated.
-- Configuring done
CMake Error at CMakeLists.txt:58 (target_link_libraries):
Error evaluating generator expression:
$<TARGET_PROPERTY:torch_cpu,INTERFACE_COMPILE_DEFINITIONS>
Target "torch_cpu" not found.
CMake Error at CMakeLists.txt:58 (target_link_libraries):
Error evaluating generator expression:
$<TARGET_PROPERTY:torch,INTERFACE_COMPILE_DEFINITIONS>
Target "torch" not found.
CMake Error at CMakeLists.txt:58 (target_link_libraries):
Error evaluating generator expression:
$<TARGET_PROPERTY:torch_cpu,INTERFACE_INCLUDE_DIRECTORIES>
Target "torch_cpu" not found.
CMake Error at CMakeLists.txt:58 (target_link_libraries):
Error evaluating generator expression:
$<TARGET_PROPERTY:torch,INTERFACE_INCLUDE_DIRECTORIES>
Target "torch" not found.
CMake Error:
Error evaluating generator expression:
$<TARGET_PROPERTY:torch_cpu,INTERFACE_SYSTEM_INCLUDE_DIRECTORIES>
Target "torch_cpu" not found.
CMake Error:
Error evaluating generator expression:
$<TARGET_PROPERTY:torch_cpu,INTERFACE_INCLUDE_DIRECTORIES>
Target "torch_cpu" not found.
CMake Error:
Error evaluating generator expression:
$<TARGET_PROPERTY:torch,INTERFACE_SYSTEM_INCLUDE_DIRECTORIES>
Target "torch" not found.
CMake Error:
Error evaluating generator expression:
$<TARGET_PROPERTY:torch,INTERFACE_INCLUDE_DIRECTORIES>
Target "torch" not found.
CMake Error at CMakeLists.txt:58 (target_link_libraries):
Error evaluating generator expression:
$<TARGET_PROPERTY:torch_cpu,INTERFACE_COMPILE_OPTIONS>
Target "torch_cpu" not found.
CMake Error at CMakeLists.txt:58 (target_link_libraries):
Error evaluating generator expression:
$<TARGET_PROPERTY:torch,INTERFACE_COMPILE_OPTIONS>
Target "torch" not found.
CMake Warning at CMakeLists.txt:49 (add_executable):
Cannot generate a safe runtime search path for target FV_test because files
in some directories may conflict with libraries in implicit directories:
runtime library [libpng16.so.16] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/home/rika/anaconda3/lib
runtime library [libz.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/home/rika/anaconda3/lib
Some of these libraries may not be found correctly.
CMake Error at CMakeLists.txt:58 (target_link_libraries):
Error evaluating generator expression:
$<TARGET_PROPERTY:torch_cpu,INTERFACE_COMPILE_DEFINITIONS>
Target "torch_cpu" not found.
CMake Error at CMakeLists.txt:58 (target_link_libraries):
Error evaluating generator expression:
$<TARGET_PROPERTY:torch,INTERFACE_COMPILE_DEFINITIONS>
Target "torch" not found.
CMake Error at CMakeLists.txt:58 (target_link_libraries):
Error evaluating generator expression:
$<TARGET_PROPERTY:torch_cpu,INTERFACE_INCLUDE_DIRECTORIES>
Target "torch_cpu" not found.
CMake Error at CMakeLists.txt:58 (target_link_libraries):
Error evaluating generator expression:
$<TARGET_PROPERTY:torch,INTERFACE_INCLUDE_DIRECTORIES>
Target "torch" not found.
CMake Warning at /home/rika/Desktop/LibtorchPort/FV/CMakeLists.txt:68 (add_library):
Cannot generate a safe runtime search path for target FV because files in
some directories may conflict with libraries in implicit directories:
runtime library [libpng16.so.16] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/home/rika/anaconda3/lib
runtime library [libz.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/home/rika/anaconda3/lib
Some of these libraries may not be found correctly.
CMake Warning at /home/rika/Desktop/LibtorchPort/AntiSpoofer/CMakeLists.txt:57 (add_library):
Cannot generate a safe runtime search path for target AntiSpoofer because
files in some directories may conflict with libraries in implicit
directories:
runtime library [libpng16.so.16] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/home/rika/anaconda3/lib
runtime library [libz.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/home/rika/anaconda3/lib
Some of these libraries may not be found correctly.
CMake Warning at /home/rika/Desktop/LibtorchPort/Blinker/CMakeLists.txt:46 (add_library):
Cannot generate a safe runtime search path for target Blinker because files
in some directories may conflict with libraries in implicit directories:
runtime library [libpng16.so.16] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/home/rika/anaconda3/lib
runtime library [libz.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/home/rika/anaconda3/lib
Some of these libraries may not be found correctly.
-- Generating done
CMake Generate step failed. Build files cannot be regenerated correctly.
And this is the CMakeLists.txt that I'm using for FV_Test.
cmake_minimum_required(VERSION 3.11)
project(FV_Test)
set(CMAKE_CXX_STANDARD 17)
find_package(OpenCV REQUIRED)
find_package(Protobuf REQUIRED)
if ("${TORCH_LIB_DIRS}" STREQUAL "")
set(TORCH_LIB_DIRS /home/rika/libtorch-cxx11-abi-shared-with-deps-1.6.0+cpu/libtorch/lib)
endif()
get_filename_component(PARENT_DIR ${PROJECT_SOURCE_DIR} DIRECTORY)
if(NOT TARGET FV)
add_subdirectory(${PARENT_DIR}/FV ${PARENT_DIR}/FV/build)
endif()
set(CMAKE_INSTALL_PREFIX ${PARENT_DIR}/built_stuff)
include_directories(${PARENT_DIR}/Dependencies/include ${OpenCV_INCLUDE_DIRS} ${Protobuf_INCLUDE_DIRS}) #
LINK_DIRECTORIES(${TORCH_LIB_DIRS})
LINK_DIRECTORIES(${PARENT_DIR}/AntiSpoofer/build)
LINK_DIRECTORIES(${PARENT_DIR}/Blinker/build)
LINK_DIRECTORIES(${PARENT_DIR}/FV/build)
add_executable(FV_test ./FV_Test.cpp )
target_link_directories(FV_test PUBLIC ${PARENT_DIR}/AntiSpoofer/build)
target_link_directories(FV_test PUBLIC ${PARENT_DIR}/Blinker/build)
target_link_directories(FV_test PUBLIC ${PARENT_DIR}/FV/build)
# Link
target_link_libraries(FV_test ${OpenCV_LIBS})
target_link_libraries(FV_test ${Protobuf_LIBRARIES})
target_link_libraries(FV_test FV)
target_link_libraries(FV_test Blinker)
install(TARGETS FV_test DESTINATION bin)
Why am I seeing this behavior and how can I solve this?
If the problem is really depicted in the following comment:
As far as I understand, the core of the problem is: 1. In subdirectory use find_package(Torch REQUIRED) and then link some library with a Torch library via target_link_libraries(mylib ${TORCH_LIBRARIES}). 2. Linking with that library in the outer directory: target_link_libraries(myexe mylib). For some (unknown) reason, during the last link CMake tries to evaluate generator expressions for torch_cpu. But this is an IMPORTED target, which is created in the subdirectory, so it cannot be accessed from the outer directory. – Tsyvarev Sep 27 '20 at 8:15
I ran into the same problem with Pytorch. The fix that worked for me was to link the torch libraries privately: target_link_libraries(mylib PRIVATE ${TORCH_LIBRARIES}").
Now don't ask my why that works I wouldn't be able to answer that.

Create Portable CMake/MingGW(G++) [duplicate]

I have a problem with this CMakeLists.txt file:
cmake_minimum_required(VERSION 2.6)
SET(CMAKE_C_COMPILER C:/MinGW/bin/gcc)
SET(CMAKE_CXX_COMPILER C:/MinGW/bin/g++)
project(cmake_test)
add_executable(a.exe test.cpp)
Calling cmake with: cmake -G "MinGW Makefiles" , it fails with the following output:
c:\Users\pietro.mele\projects\tests\buildSystem_test\cmake_test>cmake -G "MinGW Makefiles" .
-- The C compiler identification is GNU 4.6.1
-- The CXX compiler identification is GNU 4.6.1
-- Check for working C compiler: C:/MinGW/bin/gcc
CMake Error: your C compiler: "C:/MinGW/bin/gcc" was not found. Please set CMAKE_C_COMPILER to a valid compiler path or name.
CMake Error: Internal CMake error, TryCompile configure of cmake failed
-- Check for working C compiler: C:/MinGW/bin/gcc -- broken
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:52 (MESSAGE):
The C compiler "C:/MinGW/bin/gcc" is not able to compile a simple test
program.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:10 (project)
CMake Error: your C compiler: "C:/MinGW/bin/gcc" was not found. Please set CMAKE_C_COMPILER to a valid compiler path or name.
CMake Error: your CXX compiler: "C:/MinGW/bin/g++" was not found. Please set CMAKE_CXX_COMPILER to a valid compiler path or name.
-- Configuring incomplete, errors occurred!
However the gcc compiler is in C:/MinGW/bin/ and it works.
Any idea?
Platform:
Windows 7
MinGW/GCC 4.6
Never try to set the compiler in the CMakeLists.txt file.
See the CMake FAQ about how to use a different compiler:
https://gitlab.kitware.com/cmake/community/wikis/FAQ#how-do-i-use-a-different-compiler
(Note that you are attempting method #3 and the FAQ says "(avoid)"...)
We recommend avoiding the "in the CMakeLists" technique because there are problems with it when a different compiler was used for a first configure, and then the CMakeLists file changes to try setting a different compiler... And because the intent of a CMakeLists file should be to work with multiple compilers, according to the preference of the developer running CMake.
The best method is to set the environment variables CC and CXX before calling CMake for the very first time in a build tree.
After CMake detects what compilers to use, it saves them in the CMakeCache.txt file so that it can still generate proper build systems even if those variables disappear from the environment...
If you ever need to change compilers, you need to start with a fresh build tree.
I had similar problem as Pietro,
I am on Window 10 and using "Git Bash".
I tried to execute >>cmake -G "MinGW Makefiles", but I got the same error as Pietro.
Then, I tried >>cmake -G "MSYS Makefiles", but realized that I need to set my environment correctly.
Make sure set a path to C:\MinGW\msys\1.0\bin and check if you have gcc.exe there. If gcc.exe is not there then you have to run C:/MinGW/bin/mingw-get.exe and install gcc from MSYS.
After that it works fine for me
Using with FILEPATH option might work:
set(CMAKE_CXX_COMPILER:FILEPATH C:/MinGW/bin/gcc.exe)
I had the same issue. And in my case the fix was pretty simple. The trick is to simply add the ".exe" to your compilers path. So, instead of :
SET(CMAKE_C_COMPILER C:/MinGW/bin/gcc)
It should be
SET(CMAKE_C_COMPILER C:/MinGW/bin/gcc.exe)
The same applies for g++.

CMake: Set zlib path

I'm trying to compile libzip on Windows using CMake to generate makefiles. Libzip needs zlib so I'm doing the following:
mkdir build
cd build
cmake -DZLIB_LIBRARY=../../../zlib-1.2.11 -DZLIB_INCLUDE_DIR=../../../zlib-1.2.11 ..
This doesn't work, however. I get the following error:
CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.2/Modules/FindPackageHandleStandardArgs.cmake:138 (message):
Could NOT find ZLIB (missing: ZLIB_LIBRARY ZLIB_INCLUDE_DIR)
Why is that? I have defined ZLIB_LIBRARY and ZLIB_INCLUDE_DIR to point to the latest zlib.
I've also tried the following:
mkdir build
cd build
cmake .. -DZLIB_LIBRARY=../../../zlib-1.2.11 -DZLIB_INCLUDE_DIR=../../../zlib-1.2.11
When I run CMake like this, I get the following two warnings:
CMake Warning:
Manually-specified variables were not used by the project:
ZLIB_INCLUDE_DIR
ZLIB_LIBRARY
In comparison to the first approach, however, build files are now written to my build directory. When running nmake, however, only zlib seems to get built. libzip itself isn't built at all.
I'm out of ideas here. What am I doing wrong?
To answer my own question, using relative paths for ZLIB_LIBRARY and ZLIB_INCLUDE_DIR was the problem. When using absolute paths, it works just fine. Furthermore, ZLIB_LIBRARY needs to point to the library itself. Here is my final build line which works:
cmake -DZLIB_INCLUDE_DIR=d:\mystuff\zlib-1.2.11 -DZLIB_LIBRARY=d:\mystuff\zlib-1.2.11\build\zlibstatic.lib -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Release ..

Absolute paths for the include and library directories when cmake with flag CMAKE_BUILD_TYPE

Can you help me with this problem?
I configured the client build when built NextCloud (Owncloud) in desktop client. I cloned git://github.com/owncloud/client.git and created sub-dir named client-build. I got an error when typed "cmake -DCMAKE_BUILD_TYPE="Debug" .." in MinGW
-- Building for: NMake Makefiles
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:8 (project): The CMAKE_C_COMPILER: cl is not a full path and was not found in the PATH.
I set path for g++ and c in MinGW. Link here: https://doc.owncloud.org/desktop/2.3/building.html#generic-build-instructions