Im use CMake to generate visual studio 2013 solution. Next im try to build it, but get follow error:
Building NVCC (Device) object modules/core/CMakeFiles/cuda_compile.dir/src/cuda/Debug/cuda_compile_generated_gpu_mat.cu.obj
nvcc fatal : Unsupported gpu architecture 'compute_11'
Im try version 2.10 and 3.0 with cuda 6.5 and 7.0.
CUDA_ARCH_BIN set to : 1.1 1.2 1.3 2.0 2.1(2.0) 3.0 3.5
Another option.
Ubuntu 14.04, GTX Titan X, opencv-2.4.10
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_TIFF=ON -D BUILD_EXAMPLES=ON -D CUDA_GENERATION=Auto -D BUILD_NEW_PYTHON_SUPPORT=ON ..
I also applied the patch,
but I'm not sure whether it ended up being needed. I had tried with and withoutCUDA_GENERATION=Maxwell but Maxwell isn't detected. I did not try CUDA_GENERATION=Auto prior to the patch, that's why I don't know for sure.
When using cmake to do configurations, set the option CUDA_GENERATION to specific your GPU architecture. I ran across the same error and tried this to work out the problem.
Following up on Yun's answer (could not leave comment), this worked for me and shows a possible value for CUDA_GENERATION:
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D CUDA_GENERATION=Kepler ..
(Ubuntu 12.04 and 14.04, GTX Titan, and OpenCV 2.4.11 and 3.0.0.)
You can use CUDA_GENERATION to specify the corresponding generation code name for your GPU architecture.
Here's the relevant opencv cmake code that parses the CUDA_GENERATION value:
set(__cuda_arch_ptx "")
if(CUDA_GENERATION STREQUAL "Fermi")
set(__cuda_arch_bin "2.0")
elseif(CUDA_GENERATION STREQUAL "Kepler")
set(__cuda_arch_bin "3.0 3.5 3.7")
elseif(CUDA_GENERATION STREQUAL "Maxwell")
set(__cuda_arch_bin "5.0 5.2")
elseif(CUDA_GENERATION STREQUAL "Pascal")
set(__cuda_arch_bin "6.0 6.1")
elseif(CUDA_GENERATION STREQUAL "Volta")
set(__cuda_arch_bin "7.0")
elseif(CUDA_GENERATION STREQUAL "Auto")
execute_process( COMMAND "${CUDA_NVCC_EXECUTABLE}" ${CUDA_NVCC_FLAGS} "${OpenCV_SOURCE_DIR}/cmake/checks/OpenCVDetectCudaArch.cu" "--run"
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/"
RESULT_VARIABLE _nvcc_res OUTPUT_VARIABLE _nvcc_out
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT _nvcc_res EQUAL 0)
message(STATUS "Automatic detection of CUDA generation failed. Going to build for all known architectures.")
else()
set(__cuda_arch_bin "${_nvcc_out}")
string(REPLACE "2.1" "2.1(2.0)" __cuda_arch_bin "${__cuda_arch_bin}")
endif()
endif()
And the wikipedia CUDA page has a nice table for mapping your video card to the right microarchitecture code name (sorry, it's too large to reproduce here):
https://en.wikipedia.org/wiki/CUDA#GPUs_supported
For example, my middling-2012 Macbook Pro has an antique GeForce GT 650M, which the wikipedia table indicates uses the Kepler microarchitecture. Therefore, I use this in my cmake command line:
cmake -D CUDA_GENERATION="Kepler" ...
and the opencv script converts that to "3.0 3.5 3.7" when it displays the config summary, and passes on the corresponding flags to nvcc.
In my case, before setting this properly, I was getting errors about compute_70 not supported. Apparently, there is still an open issue in the opencv tracker as of today (2017-10-07) about auto-detection not working properly.
Thank you,
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D CUDA_GENERATION=Kepler ..
This let me install opencv-2.4.9.
If you want to know more detaills check this link.
This is because of your gpu type is mismatching.
You have to define CUDA_GENERATION explicitly.
In my side, I could find 3 types of CUDA_GENERATION; Auto, Kepler, Fermi.
When I set CUDA_GENERATION as Kepler, compute_11 changed to compute_30 and build successful.
You should set with cmake these entries CUDA_ARCH_BIN = 3.2 and CUDA_ARCH_PTX = 3.2
Hope it helps.
Regards
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_TIFF=ON -D BUILD_EXAMPLES=ON -D CUDA_GENERATION=Kepler -D BUILD_NEW_PYTHON_SUPPORT=ON ..
worked for me for OpenCV 2.4.11
Related
I am trying to build LLVM compilers so that I can enable OpenMP on the Apple M1.
I am using the LLVM development tree, (since I saw some OpenMP runtime go into that for this recently).
I have ended up with this script to invoke cmake:
# Xcode, Ninja
BUILD_SYSTEM=Ninja
BUILD_TAG=Ninja
cmake ../llvm \
-G$BUILD_SYSTEM -B ${BUILD_TAG}_build \
-DCMAKE_OSX_ARCHITECTURES='arm64' \
-DCMAKE_C_COMPILER=`which clang` \
-DCMAKE_CXX_COMPILER=`which clang++` \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_BUILD_WITH_INSTALL_RPATH=1 \
-DCMAKE_INSTALL_PREFIX=$HOME/software/clang-12.0.0/arm64 \
-DLLVM_ENABLE_WERROR=FALSE \
-DLLVM_TARGETS_TO_BUILD='AArch64' \
-DLLVM_ENABLE_PROJECTS='clang;openmp,polly' \
-DLLVM_DEFAULT_TARGET_TRIPLE='aarch64-apple-darwin20.1.0'
The compilers used here are
$ /usr/bin/clang --version
Apple clang version 12.0.0 (clang-1200.0.32.27)
Target: arm64-apple-darwin20.1.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
ninja can then successfully build clang, clang++ and the OpenMp runtime and install them. (As simple, Arm64 images targeting Arms64)
$ file ~/software/clang-12.0.0/arm64/bin/clang
/Users/jcownie/software/clang-12.0.0/arm64/bin/clang: Mach-O 64-bit executable arm64
$ ~/software/clang-12.0.0/arm64/bin/clang --version
clang version 12.0.0 (https://github.com/llvm/llvm-project.git 879c15e890b4d25d28ea904e92497f091f796019)
Target: aarch64-apple-darwin20.1.0
Thread model: posix
InstalledDir: /Users/jcownie/software/clang-12.0.0/arm64/bin
Which all looks sane, except that when I try to compile anything with them they are missing the include path to get system headers.
$ ~/software/clang-12.0.0/arm64/bin/clang hello.c
hello.c:1:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
^~~~~~~~~
1 error generated.
So, after all that,
Does anyone know how to fix that include path problem?
Does anyone know how to configure and build a fat binary for the compilers (and libraries) so that the x86_64 embedded compiler targets x86_64 and the aarch64 binary aarch64? (This is what the Xcode clang and clang++ do...)
My attempt at this ended up with a compiler fat binary where both architectures targeted x86_64 :-(
Thanks
You can set -DDEFAULT_SYSROOT=/path/to/MacOSX11.1.sdk at build time or do export SDKROOT=/path/to/MacOSX11.1.sdk at runtime.
You need to compile with clang -arch arm64 -arch x86_64 to get a fat binary out of clang. You need to do this for Apple clang as well.
UPDATED 8 Feb 2021
Homebrew now supports the M1 based Arm machines, so using that is a better answer than the one below.
The info below is potentially still useful if you want to do this on your own, but using brew is likely to be much simpler.
Pre-brew answer
I haven't found a clean solution, but in case it helps anyone else, I do have a horrible hack.
The full recipe, then is configure with this script, then build and install.
# Xcode, Ninja
BUILD_SYSTEM=Ninja
BUILD_TAG=ninja
INSTALLDIR=$HOME/software/clang-12.0.0/arm64
cmake ../llvm \
-G$BUILD_SYSTEM -B ${BUILD_TAG}_build \
-DCMAKE_OSX_ARCHITECTURES='arm64' \
-DCMAKE_C_COMPILER=`which clang` \
-DCMAKE_CXX_COMPILER=`which clang++` \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=$INSTALLDIR \
-DLLVM_LOCAL_RPATH=$INSTALLDIR/lib \
-DLLVM_ENABLE_WERROR=FALSE \
-DLLVM_TARGETS_TO_BUILD='AArch64' \
-DLLVM_DEFAULT_TARGET_TRIPLE='aarch64-apple-darwin20.1.0' \
-DDEFAULT_SYSROOT="$(xcrun --show-sdk-path)" \
-DLLVM_ENABLE_PROJECTS='clang;openmp;polly;clang-tools-extra;libcxx;libcxxabi' \
# -DLLVM_ENABLE_PROJECTS='clang;openmp;polly'
That gives a compiler that finds the right headers, but won't link successfully if OpenMP is used because it doesn't pass on any useful -L path or add a necessary rpath.
To overcome that I created a small shell script that sits in my ~/bin, at the front of my $PATH, which adds those extra linker flags.
#
# A truly awful hack, but it seems necessary.
# Install this with execute permissions as clang and clang++ in
# a directory early in your path, so that it is executed when clang or
# clang++ is needed.
#
# For brew...
INSTALLDIR=/usr/local/opt/llvm
# For a local build.
INSTALLDIR=${HOME}/software/clang-12.0.0/arm64/
# Find out the name of this file, and then invoke the same file in the
# compiler installation, adding the necessary linker directives
CMD=`echo $0 | sed "s/\/.*\///"`
${INSTALLDIR}/bin/${CMD} -L${INSTALLDIR}/lib -Wl,-rpath,${INSTALLDIR}/lib $*
I am not recommending this particularly; there should clearly be a better way to make it work, but it'll do for now, and lets me get back to using the compiler rather than building it!
I was able to build with -DDEFAULT_SYSROOT="$(xcrun --show-sdk-path)" -DCMAKE_INSTALL_PREFIX=/Users/foo/lokal/ and install into the lokal/bin lokal/lib path. Once that is done you can use LD_LIBRARY_PATH=/Users/foo/lokal/lib and all the libraries should be found without mucking with anything else rpath related.
I am trying to install OpenCV3.1 on my Ubuntu 16.04 for development in QT5. Sadly, building it from source always errors out due to undefined references (see below).
I used the following:
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D WITH_V4L=ON -D WITH_FFMPEG=ON -D WITH_OPENGL=ON -D BUILD_TIFF=ON -D WITH_VTK=ON..
And it works fine. But building it always produces this error
../../lib/libopencv_viz.so.3.1.0: undefined reference to `vtkSTLReader::New()'
../../lib/libopencv_viz.so.3.1.0: undefined reference to `vtkOBJReader::New()'
collect2: error: ld returned 1 exit status
modules/viz/CMakeFiles/opencv_test_viz.dir/build.make:232: recipe for target 'bin/opencv_test_viz' failed
make[2]: *** [bin/opencv_test_viz] Error 1
CMakeFiles/Makefile2:3358: recipe for target 'modules/viz/CMakeFiles/opencv_test_viz.dir/all' failed
make[1]: *** [modules/viz/CMakeFiles/opencv_test_viz.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
Of course I googled and tried everything I found. Tried several different cmake flags (or rather, without any), tried reinstalling libvtk5-dev and also tried libvtk6-dev and even build vtk7.1 from source, since I am assuming something is missing from there.
I also tried adding the opencv_contrib via
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D WITH_V4L=ON -D WITH_FFMPEG=ON -D WITH_OPENGL=ON -D BUILD_TIFF=ON -D WITH_VTK=ON -D BUILD_EXAMPLES=ON -D OPENCV_EXTRA_MODULES_PATH=/home/user/opencv/opencv-3.1.0/opencv_contrib/modules ..
But that already produced the following error
CMake Error at opencv_contrib/modules/text/CMakeLists.txt:22 (ocv_add_testdata): `Unknown CMake command "ocv_add_testdata".
Also please note that I did upgrade/update all the packages that are listed here and here
So basically after two days randomly trying all the possible solutions I could find via google, I am now asking here.
Hopefully someone knows how to fix this, thank you!
Edit: I only get these problems with OpenCV3.1. I do have a working OpenCV 2.4.13
Same happend with me. It was working and suddenly I got the same error. I re-pulled OpenCV 3.1 and it worked again.
It seems that the guys updated something both in Extra Modules and in OpenCV and you have just pull the extra modules.
For the second part, it looks like someone messed up the opencv_contrib/modules/text/CMakeLists.txt
Just edit this file and remove the lines at the end:
ocv_add_testdata(samples/ contrib/text
FILES_MATCHING PATTERN "*.xml" PATTERN "*.xml.gz" REGEX "scenetext[0-9]+.jpg"
COMPONENT "tests"
)
just switch opencv_contrib repository to 3.1.0 tag after clone.
git checkout 3.1.0
and try to build again.
First, make sure you have successfully built and installed vtk on your system;
Then,by using command "locate STLReader" or "locate vtkOBJReader" to ensure "vtkOBJReader" or "STLReader" libs are found in some specific directories. If vtkOBJReader or STLReader related files are found. It means that vtk has changed its structure in the new version, e.g. move vtkOBJReader into a sub library vtkIOGeometry, so you have to tell cmake to find vtkIOGeometry if you want to use that class.
Last, modify opencv3/cmake/OpenCVDetectVTK.cmake, for every find_package(VTK QUIET COMPONENTS ... add an entry vtkIOGeometry.
Success!
How can I compile the VM and run Erlang programs on the Intel Xeon Phi coprocessor?
Intel Xeon Phi is not a typical x86_64 architecture, therefore it's not possible to run the official Erlang VM on it. The only way to do it is to use cross-compilation and build the VM yourself on a different (host) machine where Erlang is supported, so that it runs on a target system (Phi in this case).
Xeon Phi also supports slightly different instruction set than a typical x86_64 architecture, so you also need to edit the code. If you just cross-compile the VM without touching the code, you will probably get an error:
/tmp/iccvaLP3vas_.s: Assembler messages:
/tmp/iccvaLP3vas_.s:25794: Error: `mfence' is not supported on `k1om'
So first of all you need to add #ifndef clauses around memory fence instructions, which are not supported on Phi (mfence, lfence and sfence). This boils down to opening the erts/include/internal/i386/ethr_membar.h file and adding following preprocessor directives:
#ifndef __MIC__
...
#endif
around __asm__ statements in funtions ethr_mfence__, ethr_sfence__ and ethr_lfence__ e.g.
static __inline__ void
ethr_mfence__(void)
{
#if ETHR_SIZEOF_PTR == 4
if (ETHR_X86_RUNTIME_CONF_HAVE_NO_SSE2__)
ETHR_NO_SSE2_MEMORY_BARRIER__;
else
#endif
#ifndef __MIC__
__asm__ __volatile__ ("mfence\n\t" : : : "memory");
#endif
}
Now you can try to cross-compile it. First download the sources (in my case Erlang VM 17.5), then run:
$ cd otp_src_17.5
$ export ERL_TOP=`pwd`;
$ ./configure \
--host=k1om-unknown-linux-gnu \
--build=x86_64-pc-linux-gnu \
--without-termcap \
--without-javac \
--without-ssl \
--prefix=/path/to/my/new_installation \
CC=icc \
CFLAGS=-mmic \
LDFLAGS=-mmic \
DED_LD=icc \
DED_LDFLAGS="-mmic -shared -Wl,-Bsymbolic" \
DED_LD_FLAG_RUNTIME_LIBRARY_PATH="-Wl,-R"
$ make
$ make install
icc is the official Intel Compiler and -mmic flag is required for compiling for Xeon Phi. The host and build flags are the systems/architectures of respectively the machine where you compile and the machine which you compile for (Phi). In my case they had following values, but if it's different for you, you might want to use the config.guess script which automatically detects your OS/CPU architecture.
$ ./config.guess
$ x86_64-pc-linux-gnu
And that's it! Now you should be able to ssh on your Phi and run Erlang.
$ ssh my-phi-coprocessor
$ cd /path/to/my/new_installation/
$ export PATH=`pwd`/bin:$PATH;
$ erl -version
Erlang (SMP,ASYNC_THREADS) (BEAM) emulator version 6.4
It seems very easy when compiling opencv library for the release mode:
cmake -D CMAKE_BUILD_TYPE=RELEASE ../
or cmake DCMAKE_BUILD_TYPE:string=Release ../
However, the created project is still in Debug mode, and I was wondering how I could do in order to make the project in a release mode. Thanks.
The configuration name is case-sensitive, and the CMake command line arg needs a - at the front. The arg type (i.e. string in your example) is optional, so the command should be:
cmake -DCMAKE_BUILD_TYPE=Release ..
if(DEFINED CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING “Choose the type of building”)
else()
set(CMAKE_BUILD_TYPE Debug CACHE STRING “Choose the type of build”)
endif()
set(CMAKE_CONFIGURATION_TYPES ${CMAKE_BUILD_TYPE} CACHE STRING “” FORCE)
cmake -DCMAKE_BUILD_TYPE=Release ..
I am trying to build the OpenCV samples which come with the source package and I get the following:
CMake Error at CMakeLists.txt:10 (ocv_check_dependencies):
Unknown CMake command "ocv_check_dependencies".
I did install OpenCV using
cmake .
make
sudo make install
and I got a tutorial snippet working (thus I suppose it is installed correctly as a library). However, compiling the samples does not work.
I guess I have to somehow configure CMake to have “ocv_check_dependencies” - but how? I am lost!
Actually for OpenCV 2.4.4 beta the root CMakeList.txt file says:
OCV_OPTION(BUILD_EXAMPLES "Build all examples"
-DBUILD_EXAMPLES=ON worked just fine for me.
I got it.
In order to build the samples one has to change the default configuration for cmake by providing it via -D. What I did wrong was that I tried to execute cmake from within the samples directory.
The proper way to build the samples is invoking cmake like so (from within the root directory of the unpacked archive):
cmake -DBUILD_SAMPLES .
which will turn samples ON. One can proceed using make, make install than. The samples can be found in bin after building.
See also FAQ
How to compile OpenCV sample code ?
# For OpenCV 3
cd /path/to/opencv/samples/cpp/
#Compile
g++ -ggdb `pkg-config --cflags --libs opencv` facedetect.cpp -o facedetect
#run
./facedetect
Works for me.
googled from this link
mydragonisland's build instructions almost worked for me; with a minor reordering and including accents:
g++ facedetect.cpp -o facedetect `pkg-config --libs opencv`
The macro 'ocv_check_dependencies' is defined in: your_path_to/opencv/cmake/OpenCVModule.cmake
# ensures that all passed modules are available
# sets OCV_DEPENDENCIES_FOUND variable to TRUE/FALSE
macro(ocv_check_dependencies)
set(OCV_DEPENDENCIES_FOUND TRUE)
foreach(d ${ARGN})
if(d MATCHES "^opencv_[^ ]+$" AND NOT HAVE_${d})
set(OCV_DEPENDENCIES_FOUND FALSE)
break()
endif()
endforeach()
endmacro()
The top level CMakeLists.txt contains 'include' commands for files from opencv/cmake/ . Which is why the macro is available when you compile by calling cmake from the root of the opencv sources.
Reason
error message context:
CMake Error at CMakeLists.txt:10 (ocv_check_dependencies):
Unknown CMake command "ocv_check_dependencies".
This error message happens because cmake can't find the definition of ocv_check_dependencies
That's why the console said Unknown CMake command
Solution
If cmake cannot find where ocv_check_dependencies is defined
Just like #Nick Hockings Said:
ocv_check_dependencies is a macro defined in Your/OpenCV/path/OpenCVModule.cmake
macro(ocv_check_dependencies)
set(OCV_DEPENDENCIES_FOUND TRUE)
foreach(d ${ARGN})
if(d MATCHES "^opencv_[^ ]+$" AND NOT HAVE_${d})
set(OCV_DEPENDENCIES_FOUND FALSE)
break()
endif()
endforeach()
endmacro()
The fastest way is to copy this snippet above to your CMakeList.txt file right above where ocv_check_dependencies is
Therefore, cmake can finally understand what it is
That should do the trick, i hope no one else will bother with this question in the future
I got similar errors. My approach is as following:
1) cd xxx/samples 2) mkdir build 3) cd build 4) cmake .. 5) make
Now it works. We could not build individual project under their source files.
Following steps works for me.
Export toolchain path.
cd opencv-3.3.0/samples
cross_cmake &&
cross_make
cd opencv-3.3.0/samples/cpp/