Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"In-source builds are not allowed" in cmake

I'm new to cmake, and I'm only using it to install opencv on my ubuntu linux. Here's the command I ran: cmake -DCMAKE_BUILD_TYPE=Release DCMAKE_INSTALL_PREFIX=/home/jinha/OCV/source

Then it returns the error:

FATAL: In-source builds are not allowed. You should create separate directory for build files.

My current directory, ~/OCV/build/opencv, does contain the CMakefiles.txt file, so that's not the problem. I tried to change the directory in my command, but they all raise the same error. I saw the other answers on this issue, so I erased CMakeFiles directory and CMakeCache.txt file every time before I ran the command, but none of them worked.
Thanks.

like image 775
WannabeArchitect Avatar asked Aug 05 '17 04:08

WannabeArchitect


People also ask

What is an out of source build?

“Out-of-source build” is a good practice of keeping separate the generated files of the binary tree from the source files of the source tree. CMake does support the contrary “in-source build” layout, but such an approach has no real benefit and is not recommended.

What does CMake -- build do?

CMake is a cross-platform build system generator. Projects specify their build process with platform-independent CMake listfiles included in each directory of a source tree with the name CMakeLists. txt. Users build a project by using CMake to generate a build system for a native tool on their platform.


2 Answers

It wants you to create a separate build directory (anywhere), and run cmake there. For example:

mkdir my_build_dir cd my_build_dir rm ../CMakeCache.txt cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/home/jinha/OCV/source 

Note the .. in this example telling cmake where to look for the source.

In case you didn't remove CMakeCache.txt before building again, it will still show this error. So, please remember to delete CMakeCache.txt first before running cmake.

like image 164
John Zwinck Avatar answered Sep 29 '22 20:09

John Zwinck


After you have success downloaded and unzipped OpenCV sources from sources you need create simple command-file install.sh. For example, your working dir will be /home/user/myopencv

So /home/user/myopencv/install.sh will be contain next code:

#!/bin/bash

rm CMakeCache.txt
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=/usr/local 
make
make install
make clean

Next

chmod 777 install.sh
./install.sh

And after the all you will get those executable files:

root@cartman:/usr/local/bin# ls -las | grep opencv
 32 -rwxr-xr-x  1 root root   29888 апр 20 18:10 opencv_annotation
244 -rwxr-xr-x  1 root root  247608 апр 20 18:10 opencv_createsamples
244 -rwxr-xr-x  1 root root  247504 апр 20 18:10 opencv_haartraining
 20 -rwxr-xr-x  1 root root   18600 апр 20 18:10 opencv_performance
288 -rwxr-xr-x  1 root root  294592 апр 20 18:10 opencv_traincascade
 16 -rwxr-xr-x  1 root root   14288 апр 20 18:10 opencv_version
 60 -rwxr-xr-x  1 root root   61040 апр 20 18:10 opencv_visualisation

Enjoy!

like image 31
Orlov Const Avatar answered Sep 29 '22 21:09

Orlov Const