[英]Compiler ignores my includes -I for new library version
I think that this question is not specifically on OpenCV , it seems more an include problem, so please read it even if you don't know the library. 我认为这个问题不是专门针对OpenCV ,它似乎是一个包含问题,因此即使您不知道该库也请阅读它。
There is an old version of a library (OpenCV) that's installed in /usr/local
on the remote machine where I'm working on and where I don't have sudo
access. 有一个旧版本的库(OpenCV)安装在我正在工作且没有
sudo
访问权限的远程计算机上的/usr/local
。
I've installed an updated version in my local environment /home/spm1428/local
and I'm compiling it by using -I/home/spm1428/local/include/opencv
and -I/home/spm1428/local/include/opencv2
. 我已经在本地环境
/home/spm1428/local
安装了更新版本,并且正在使用-I/home/spm1428/local/include/opencv
和-I/home/spm1428/local/include/opencv2
。
However, in a file where #include "opencv/opencv.hpp"
I get this error: 但是,在
#include "opencv/opencv.hpp"
文件中,出现此错误:
In file included from /usr/local/include/opencv2/opencv.hpp:77:0,
from /home/spm1428/CloudCache/Utilities/Utility.hpp:11,
from ../Descriptors/Descriptor.cpp:17:
/usr/local/include/opencv2/highgui/highgui.hpp:165:25: error: redeclaration of ‘IMREAD_UNCHANGED’
It's an error given by the old version of the library installed in /usr/local
, but I told him to use the local version using -I
! 这是
/usr/local
安装的库的旧版本给出的错误,但是我告诉他使用-I
使用本地版本!
So it seems that the compiler ignores my -I
directives and instead gives the priority to /usr/local/include
因此,似乎编译器会忽略我的
-I
指令,而是将优先级赋予/usr/local/include
Why this happens? 为什么会这样?
If you wonder the whole compiling command is: 如果您想知道整个编译命令是:
g++ -DCC_DISABLE_CUDA -I/home/spm1428/CloudCache -I/home/spm1428/local/include/opencv -I/home/spm1428/local/include/opencv2 -I/usr/include/boost -I/home/spm1428/vlfeat -O3 -g -Wall -c -fopenmp -std=c++11 -c -o Descriptor.o ../Descriptors/Descriptor.cpp
This error happens both using #include <opencv2/core.hpp>
and include "opencv2/core.hpp"
. 使用
#include <opencv2/core.hpp>
并include "opencv2/core.hpp"
#include <opencv2/core.hpp>
发生此错误。
UPDATE OF NEW ERROR: 更新新错误:
Changing: #incldue <opencv2/opencv.hpp>
to #include "opencv2/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
solved the problem for some reason. 更改:
#incldue <opencv2/opencv.hpp>
更改为#include "opencv2/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
由于某种原因解决了该问题。 However, now when I compile: 但是,现在我编译时:
g++ -DCC_DISABLE_CUDA -I/home/spm1428/local/include -I/home/spm1428/CloudCache -I/home/spm1428/local/include/opencv -I/home/spm1428/local/include/opencv2 -I/usr/include/boost -I/home/spm1428/vlfeat -O3 -g -Wall -c -fopenmp -std=c++11 -c -o SIFTOpenCV.o ../Descriptors/SIFTOpenCV.cpp
I get this error: 我收到此错误:
../Descriptors/SIFTOpenCV.cpp:31:9: error: ‘class cv::Feature2D’ has no member named ‘detectAndCompute’
sift->detectAndCompute(img, cv::Mat(), pts, descriptors);
SIFTOpenCV.cpp
includes SIFTOpenCV.hpp
, which includes #include "opencv2/xfeatures2d.hpp"
. SIFTOpenCV.cpp
包含SIFTOpenCV.hpp
,其中包含#include "opencv2/xfeatures2d.hpp"
。 I think that this error is related somehow to the previous one. 我认为此错误与上一个错误有关。
The weirdest thing is that this compiles correctly on my local machine (where I have sudo
access and I installed it /usr/local
) 最奇怪的是,这在我的本地计算机(我具有
sudo
访问权限,并且我将其安装在/usr/local
)上正确编译了
This is the class SIFTOpenCV.hpp
: 这是类
SIFTOpenCV.hpp
:
#include "Descriptors/Descriptor.hpp"
#include <opencv2/xfeatures2d.hpp>
namespace cc{
class SIFTOpenCV : public Descriptor{
public:
SIFTOpenCV(int nFeatures=0, int nOctaveLayers=3, double contrastThreshold=0.04, double edgeThreshold=10, double sigma=1.6);
void mapParams(std::vector<std::pair<std::string,std::string>> ¶ms);
void ComputeDescriptors(cv::Mat &img, cv::Mat1f &descriptors);
private:
cv::Ptr<cv::xfeatures2d::SIFT> sift;
int nFeatures, nOctaveLayers;
double contrastThreshold, edgeThreshold, sigma;
};
}
While Descriptor.hpp
: 而
Descriptor.hpp
:
#include "opencv2/core.hpp"
#include <string>
#include <map>
namespace cc{
class Descriptor{
public:
virtual void mapParams(std::vector<std::pair<std::string,std::string>> ¶ms) = 0;
virtual void ComputeDescriptors(cv::Mat &img, cv::Mat1f &descriptors) = 0;
virtual void ComputeDescriptors(const std::string &fileName, const std::string &imgExt, cv::Mat1f &descriptor);
virtual void ComputeDescriptors(const std::string &dirPath, const std::string &imgExt, std::vector<cv::Mat1f> &descriptors);
void setResizeDim(const size_t resizeDim);
void setSamples (const size_t samples);
void setOMP(const bool omp);
virtual ~Descriptor();
private:
void ComputeDescriptorsRange(const std::vector<std::string> &files, std::vector<cv::Mat1f> &descriptors, const int start, const int finish, size_t errors);
size_t resizeDim = 0; //comput full-size image
int samples = 0;
bool omp = true;
};
}
I found the solution by myself: executing cpp -v
returned me: 我自己找到了解决方案:执行
cpp -v
返回了我:
/usr/local/include
/usr/include
/home/spm1428/local/include
...
This means that using -I/home/spm1428/local/include
was ignored because already included, but the priority was given to the old version in /usr/local/include
. 这意味着使用
-I/home/spm1428/local/include
被忽略,因为它已包含在内,但/usr/local/include
的旧版本已被赋予优先级。
Installing OpenCV in a new local directory and include it with -I
gave the priority to the new version and solved the problem. 在新的本地目录中安装OpenCV并将其包含在
-I
,将新版本的优先级赋予优先级并解决了该问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.