- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我很困惑为什么我可以在命令行中使用 cmake
构建 C++ 程序,但不能在 CLion 中使用其“构建”功能构建程序。
这是我的 CMakeLists.txt
文件。我正在尝试使用 OpenCV 构建一个简单的图像分类程序,教程是 here .
cmake_minimum_required(VERSION 3.5.1)
project(opencvdnn )
set(CMAKE_CXX_STANDARD 14)
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable(caffe caffe.cpp)
target_link_libraries(caffe ${OpenCV_LIBS} )
案例 1:
我直接在命令行中使用以下命令和结果成功构建:
user:/DATA/opencvdnn/build$ cmake ../CMakeLists.txt
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /media/yuqiong/DATA/opencvdnn
案例二
我在我的 CLion IDE 中使用 build
功能,但失败了,声称找不到某个库。
/opt/clion-2018.2.5/bin/cmake/linux/bin/cmake --build /media/yuqiong/DATA/opencvdnn --target caffe -- -j 6
Scanning dependencies of target caffe
[ 50%] Building CXX object CMakeFiles/caffe.dir/caffe.cpp.o
/media/yuqiong/DATA/opencvdnn/caffe.cpp:5:27: fatal error: opencv2/dnn.hpp: No such file or directory
compilation terminated.
CMakeFiles/caffe.dir/build.make:62: recipe for target 'CMakeFiles/caffe.dir/caffe.cpp.o' failed
make[3]: *** [CMakeFiles/caffe.dir/caffe.cpp.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/caffe.dir/all' failed
make[2]: *** [CMakeFiles/caffe.dir/all] Error 2
CMakeFiles/Makefile2:79: recipe for target 'CMakeFiles/caffe.dir/rule' failed
make[1]: *** [CMakeFiles/caffe.dir/rule] Error 2
Makefile:118: recipe for target 'caffe' failed
make: *** [caffe] Error 2
我的问题是为什么会这样? CLion 是否使用与 cmake
工具相同的 CMake?谢谢!
如果有帮助,这是我的目录结构:
├── build
├── bvlc_googlenet.caffemodel
├── bvlc_googlenet.prototxt
├── caffe.cpp
├── cmake-build-debug
│ ├── CMakeCache.txt
│ ├── CMakeFiles
│ │ ├── 3.12.3
│ │ │ ├── CMakeCCompiler.cmake
│ │ │ ├── CMakeCXXCompiler.cmake
│ │ │ ├── CMakeDetermineCompilerABI_C.bin
│ │ │ ├── CMakeDetermineCompilerABI_CXX.bin
│ │ │ ├── CMakeSystem.cmake
│ │ │ ├── CompilerIdC
│ │ │ │ ├── a.out
│ │ │ │ ├── CMakeCCompilerId.c
│ │ │ │ └── tmp
│ │ │ ├── CompilerIdCUDA
│ │ │ │ ├── CMakeCUDACompilerId.cu
│ │ │ │ └── tmp
│ │ │ └── CompilerIdCXX
│ │ │ ├── a.out
│ │ │ ├── CMakeCXXCompilerId.cpp
│ │ │ └── tmp
│ │ ├── caffe.dir
│ │ │ ├── build.make
│ │ │ ├── cmake_clean.cmake
│ │ │ ├── CXX.includecache
│ │ │ ├── DependInfo.cmake
│ │ │ ├── depend.internal
│ │ │ ├── depend.make
│ │ │ ├── flags.make
│ │ │ ├── link.txt
│ │ │ └── progress.make
│ │ ├── clion-environment.txt
│ │ ├── clion-log.txt
│ │ ├── cmake.check_cache
│ │ ├── CMakeDirectoryInformation.cmake
│ │ ├── CMakeError.log
│ │ ├── CMakeOutput.log
│ │ ├── CMakeTmp
│ │ ├── feature_tests.bin
│ │ ├── feature_tests.c
│ │ ├── feature_tests.cxx
│ │ ├── Makefile2
│ │ ├── Makefile.cmake
│ │ ├── opencvdnn.dir
│ │ │ ├── build.make
│ │ │ ├── cmake_clean.cmake
│ │ │ ├── DependInfo.cmake
│ │ │ ├── depend.make
│ │ │ ├── flags.make
│ │ │ ├── link.txt
│ │ │ └── progress.make
│ │ ├── Progress
│ │ │ ├── 1
│ │ │ └── count.txt
│ │ ├── progress.marks
│ │ └── TargetDirectories.txt
│ ├── cmake_install.cmake
│ ├── Makefile
│ └── opencvdnn.cbp
├── CMakeCache.txt
├── CMakeFiles
│ ├── 3.12.3
│ │ ├── CMakeCCompiler.cmake
│ │ ├── CMakeCXXCompiler.cmake
│ │ ├── CMakeDetermineCompilerABI_C.bin
│ │ ├── CMakeDetermineCompilerABI_CXX.bin
│ │ ├── CMakeSystem.cmake
│ │ ├── CompilerIdC
│ │ │ ├── a.out
│ │ │ ├── CMakeCCompilerId.c
│ │ │ └── tmp
│ │ └── CompilerIdCXX
│ │ ├── a.out
│ │ ├── CMakeCXXCompilerId.cpp
│ │ └── tmp
│ ├── 3.5.1
│ │ ├── CMakeCCompiler.cmake
│ │ ├── CMakeCXXCompiler.cmake
│ │ ├── CMakeDetermineCompilerABI_C.bin
│ │ ├── CMakeDetermineCompilerABI_CXX.bin
│ │ ├── CMakeSystem.cmake
│ │ ├── CompilerIdC
│ │ │ ├── a.out
│ │ │ └── CMakeCCompilerId.c
│ │ └── CompilerIdCXX
│ │ ├── a.out
│ │ └── CMakeCXXCompilerId.cpp
│ ├── caffe.dir
│ │ ├── build.make
│ │ ├── cmake_clean.cmake
│ │ ├── DependInfo.cmake
│ │ ├── depend.make
│ │ ├── flags.make
│ │ ├── link.txt
│ │ └── progress.make
│ ├── clion-environment.txt
│ ├── cmake.check_cache
│ ├── CMakeDirectoryInformation.cmake
│ ├── CMakeOutput.log
│ ├── CMakeTmp
│ ├── feature_tests.bin
│ ├── feature_tests.c
│ ├── feature_tests.cxx
│ ├── Makefile2
│ ├── Makefile.cmake
│ ├── progress.marks
│ └── TargetDirectories.txt
├── cmake_install.cmake
├── CMakeLists.txt
├── Makefile
├── opencvdnn.cbp
├── space_shuttle.jpg
└── synset_words.txt
这是源代码,它基本上只是读取 caffe
模型并将其用于图像。
#include <opencv2/dnn.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/core/utils/trace.hpp>
using namespace cv;
using namespace cv::dnn;
#include <fstream>
#include <iostream>
#include <cstdlib>
using namespace std;
/* Find best class for the blob (i. e. class with maximal probability) */
static void getMaxClass(const Mat &probBlob, int *classId, double *classProb)
{
Mat probMat = probBlob.reshape(1, 1); //reshape the blob to 2x1000 matrix
Point classNumber;
minMaxLoc(probMat, NULL, classProb, NULL, &classNumber);
*classId = classNumber.x;
}
static std::vector<String> readClassNames(const char *filename = "synset_words.txt")
{
std::vector<String> classNames;
std::ifstream fp(filename);
if (!fp.is_open())
{
std::cerr << "File with classes labels not found: " << filename << std::endl;
exit(-1);
}
std::string name;
while (!fp.eof())
{
std::getline(fp, name);
if (name.length())
classNames.push_back( name.substr(name.find(' ')+1) );
}
fp.close();
return classNames;
}
int main(int argc, char **argv)
{
CV_TRACE_FUNCTION();
String modelTxt = "bvlc_googlenet.prototxt";
String modelBin = "bvlc_googlenet.caffemodel";
String imageFile = (argc > 1) ? argv[1] : "space_shuttle.jpg";
Net net;
try {
net = dnn::readNetFromCaffe(modelTxt, modelBin);
}
catch (cv::Exception& e) {
std::cerr << "Exception: " << e.what() << std::endl;
if (net.empty())
{
std::cerr << "Can't load network by using the following files: " << std::endl;
std::cerr << "prototxt: " << modelTxt << std::endl;
std::cerr << "caffemodel: " << modelBin << std::endl;
std::cerr << "bvlc_googlenet.caffemodel can be downloaded here:" << std::endl;
std::cerr << "http://dl.caffe.berkeleyvision.org/bvlc_googlenet.caffemodel" << std::endl;
exit(-1);
}
}
Mat img = imread(imageFile);
if (img.empty())
{
std::cerr << "Can't read image from the file: " << imageFile << std::endl;
exit(-1);
}
//GoogLeNet accepts only 224x224 BGR-images
Mat inputBlob = blobFromImage(img, 1.0f, Size(224, 224),
Scalar(104, 117, 123), false); //Convert Mat to batch of images
Mat prob;
cv::TickMeter t;
for (int i = 0; i < 10; i++)
{
CV_TRACE_REGION("forward");
net.setInput(inputBlob, "data"); //set the network input
t.start();
prob = net.forward("prob"); //compute output
t.stop();
}
int classId;
double classProb;
getMaxClass(prob, &classId, &classProb);//find the best class
std::vector<String> classNames = readClassNames();
std::cout << "Best class: #" << classId << " '" << classNames.at(classId) << "'" << std::endl;
std::cout << "Probability: " << classProb * 100 << "%" << std::endl;
std::cout << "Time: " << (double)t.getTimeMilli() / t.getCounter() << " ms (average from " << t.getCounter() << " iterations)" << std::endl;
return 0;
} //main
最佳答案
恐怕您使用命令行的第一种方法不起作用。 cmake 只会创建 make 文件。它是实际构建目标的 make 命令。您的 clion 输出表明 clion 能够成功生成 make 文件,但无法构建。如果您尝试通过命令行手动执行 make,我希望会出现相同的错误。
如果您可以通过命令行构建 camke 项目,它也应该 100% 地在 clion 中构建。
我还建议检查您的系统上是否安装了 opencv2。检查您是否有文件夹/usr/include/opencv 或者它是否是/usr/include/opencv2。由于您的 find_package(OpenCV REQUIRED) 成功,可以肯定您有本地安装。
另一种方法是查找文件 CMakeCache.txt。如果你在其中搜索 opencv,你会发现其中设置了一些 OpenCV 变量。这应该会给你一个线索。
关于c++ - opencv2 可以使用 cmake 构建但不能在 CLion "build"功能中构建?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55084061/
如何在 Mac 上的 Clion EAP 中更改默认工作目录? 每次创建新项目时,我都需要将其更改为项目位置。 最佳答案 首先,无法通过 CLion 的 GUI 更改工作目录(请参阅 Source 中
我想知道 CLion IDE 是用什么语言编写的,以及使用什么库来制作图形。 最佳答案 See this wiki post. 用Java编写 关于clion - CLion 是用什么语言和图形库制作
我已按照说明更新我的 GDB 以便与 Eigen3 一起使用。但是,CLion IDE 无法在调试面板中加载特征矩阵的内容。 本应是快速验证和调试结果的过程变成了耗时的手动打印过程(或更糟:在 cyg
我正在尝试使用 Clion 编写一个 C++ 应用程序,该应用程序使用使用 ASCII 序列的彩色控制台输出。当我在 Clion 中运行程序时,没有显示颜色。但是当我在终端中运行程序时,我可以看到颜色
使用CLion时,我发现输出有时会中断。 例如,在运行代码时: main.cpp #include int main() { int i; for (i = 0; i < 1000;
我正在寻找一种在 CLion IDE 中并行处理多个项目的方法。 现在我一次只能处理一个窗口中的每个项目,但我正在寻找类似于 Eclipse IDE(见下文)的解决方案 - 能够在侧栏上看到我不同项目
嗨,我在更改函数颜色的颜色时遇到问题。我正在使用 Material 主题,除了函数调用之外,我更改了几乎所有颜色。任何人都遇到过这个问题并知道如何解决它?它是否列在另一个标题下?我目前将它用于 C/C
大多数从可以选择构建单个文件的其他 IDE 切换过来的人都对 CLion 感到有些困惑,而 CLion 恰好没有选项。 那么如何避免将每个源文件的每个名称都添加到 CMake 中呢? 最佳答案 您正在
在 CLion 中,如何指定 C++ 编译器将在其中查找头文件的包含目录?另外,如何设置要链接的库及其库目录? 目前我正在做那些直接修改文件的任务 CMakeLists.txt : include_d
在使用 CLion 时,我发现输出有时会中断。 例如运行代码时: main.cpp #include int main() { int i; for (i = 0; i < 1000
在查看 C 库函数或系统调用的文档时,Linux 上的 CLion 会显示相应的手册页。我在 Windows 本地和适用于 Linux 的 Windows 子系统中都安装了手册和手册页。有没有办法将
在 CLion 中创建文件时,以下标题位于文件顶部: // // Created by on 14.01.18. // 有人通过 can remove this header 去 Settings
我想要查看我的 C 程序的 ASM 有很多原因,但据我发现,似乎只能查看没有 src 的 3rd 方模块的 ASM。 如何查看我的 src 的 ASM? 最佳答案 我有同样的问题,但找到了 clion
我很难让 Ctrl+V 在 CLion 中粘贴代码(我使用的是 Windows 1.1.1 版)。当我尝试粘贴使用 Ctrl+C 复制的代码时,例如网站或其他程序,它似乎只是偶尔工作。通常它会粘贴一段
CLion 有一个很好的 integration of Clang-Tidy ,但默认配置是针对现代 C++ 的。然而,我坚持使用的编译器仅为 C++03,而且 Clang-Tidy 关于使我的代码现
我正在尝试在我的 Windows 机器中将 valgrind 与 clion 结合使用。我已经完成了 setting up WSL 的步骤和 valgrind在 window 上。虽然当我尝试在我的“
使用上下文菜单,我可以通过右键单击和 new > C++ Class 在 CLion 中轻松创建 .cpp 和头文件. 头文件的扩展名为.h。如何使 .hpp 成为默认的 header 扩展? 最佳答
编译前准备 我们正常直接编译后生成的exe是没有任何图标的 那么很多exe程序都是有个性图标的那么在vs和qt中是比较简单的可是在Clion编译中怎么才能添加呢? 前提条件,本机必须配置好MinGW,
虽然在我的编程“职业”中大部分时间都使用了 Java 和 PHP,但我现在正在尝试更深入地学习 C++。为此,我使用 CLion 作为我的 IDE - 主要是因为我非常熟悉 phpStorm 和 In
您好,我用 c 语言编程,我喜欢使用 clion。有没有办法更改它在新项目中创建的默认文件的方式?我希望它创建一个 main.c 和 make 文件来反射(reflect)这一点。 最佳答案 阅读Ho
我是一名优秀的程序员,十分优秀!