简体   繁体   中英

cmake error 'the source does not appear to contain CMakeLists.txt'

I'm installing opencv in ubuntu 16.04. After installing the necessary prerequisites I used the following command:-

kvs@Hunter:~/opencv_contrib$ mkdir build
kvs@Hunter:~/opencv_contrib$ cd build
kvs@Hunter:~/opencv_contrib/build$ 
kvs@Hunter:~/opencv_contrib/build$ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX+/usr/local -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules -D BUILD_EXAMPLES=ON ..

but it produced an error:-

CMake Error: The source directory "/home/kvs/opencv_contrib" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.

I used the command provided in the folder 'module' documentation. How do I solve it? I tried the answers here at stack-overflow and a few other question but still can't figure it out.

Project Git repository here .

You should do mkdir build and cd build while inside opencv folder, not the opencv-contrib folder. The CMakeLists.txt is there.

Since you add .. after cmake, it will jump up and up (just like cd .. ) in the directory. But if you want to run cmake under the same folder with CMakeLists.txt, please use . instead of .. .

This reply may be late but it may help users having similar problem. The opencv-contrib (available at https://github.com/opencv/opencv_contrib/releases ) contains extra modules but the build procedure has to be done from core opencv (available at from https://github.com/opencv/opencv/releases ) modules.

Follow below steps (assuming you are building it using CMake GUI)

  1. Download openCV (from https://github.com/opencv/opencv/releases ) and unzip it somewhere on your computer. Create build folder inside it

  2. Download exra modules from OpenCV. (from https://github.com/opencv/opencv_contrib/releases ). Ensure you download the same version.

  3. Unzip the folder.

  4. Open CMake

  5. Click Browse Source and navigate to your openCV folder.

  6. Click Browse Build and navigate to your build Folder.

  7. Click the configure button. You will be asked how you would like to generate the files. Choose Unix-Makefile from the drop down menu and Click OK. CMake will perform some tests and return a set of red boxes appear in the CMake Window.

  8. Search for "OPENCV_EXTRA_MODULES_PATH" and provide the path to modules folder (eg /Users/purushottam_d/Programs/OpenCV3_4_5_contrib/modules)

  9. Click Configure again, then Click Generate.

  10. Go to build folder

# cd build
# make
# sudo make install
  1. This will install the opencv libraries on your computer.

I had a similar problem with another package and neither operating from a clean directory, to build from out, nor copy/paste the CMakeLists.txt file from the source to the clean directory worked. I simply solved installing by conda

An easier way to build OpenCV from source in a step by step fashion as given in this reference: Installing OpenCV from the Source is to,

step 1: install dependencies,

 sudo apt install build-essential cmake git pkg-config libgtk- 
   3-dev \libavcodec-dev libavformat-dev libswscale-dev 
   libv4l-dev \libxvidcore-dev libx264-dev libjpeg-dev 
   libpng-dev libtiff-dev \gfortran openexr libatlas-base- 
   dev python3-dev python3-numpy \libtbb2 libtbb-dev 
   libdc1394-22-dev

Step 2: create a directory opencv_build and Clone the necessary repositories as shown below,

mkdir ~/opencv_build && cd ~/opencv_build
git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git

step 3: cd into opencv directory, inside create another directory called build and cd into it,

cd ~/opencv_build/opencv
mkdir build && cd build

step 4: evoke Cmake to build OpenCV,

cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_C_EXAMPLES=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D OPENCV_GENERATE_PKGCONFIG=ON \ 
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_build/opencv_contrib/modules \
-D BUILD_EXAMPLES=ON ..

If step 4 completes successfully you should see the following line at the end of the terminal, the build has been written to the directory created in step 3, along with the following lines above this line,

configuration done generating done

step 5: To start the compilation process where -j is a flag for the number of the processor inside your machine, for example -j6 means we have 6 processors available. to verify the number of processors type nproc on the terminal then use this number after -j . To start this process, we use the following command:

make -j6 

step 6: install OpenCV, We use,

sudo make install

then check the version Of OpenCV to verify the installation:

pkg-config --modversion opencv4

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM