简体   繁体   English

cmake中的“不允许在源代码中构建”

[英]"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.我是 cmake 的新手,我只用它在我的 ubuntu linux 上安装 opencv。 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, /home/jinha/OCV/build/opencv, does contain the CMakefiles.txt file, so that's not the problem.我当前的目录 /home/jinha/OCV/build/opencv 包含 CMakefiles.txt 文件,所以这不是问题。 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 folder and CMakeCache.txt file every time before I ran the command, but none of them worked.我看到了关于这个问题的其他答案,所以我每次运行命令之前都删除了 CMakeFiles 文件夹和 CMakeCache.txt 文件,但它们都不起作用。 Thanks.谢谢。

It wants you to create a separate build directory (anywhere), and run cmake there.它希望您创建一个单独的构建目录(任何地方),并在那里运行 cmake。 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.注意这个例子中的..告诉 cmake 在哪里寻找源。

In case you didn't remove CMakeCache.txt before building again, it will still show this error.如果您在再次CMakeCache.txt之前没有删除CMakeCache.txt ,它仍然会显示此错误。 So, please remember to delete CMakeCache.txt first before running cmake .所以,请记得在运行cmake之前先删除CMakeCache.txt

After you have success downloaded and unzipped OpenCV sources from sources you need create simple command-file install.sh.源中成功下载并解压缩 OpenCV 源后,您需要创建简单的命令文件 install.sh。 For example, your working dir will be /home/user/myopencv例如,您的工作目录将是 /home/user/myopencv

So /home/user/myopencv/install.sh will be contain next code:所以 /home/user/myopencv/install.sh 将包含下一个代码:

#!/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!享受!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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