我正在尝试编译使用opencv 3.0的给定程序。我已经通过macports安装了opencv 2.x,并且一直在使用我的代码而没有任何问题。但是,给定的程序需要opencv 3.0,所以我必须自己安装在不同的位置,因为这个版本不能通过macports获得。在编辑opencv路径后,我尝试使用给定的makefile编译给定的程序。问题是我得到的编译错误似乎是链接问题,因为它查看位于由macports安装的2.x版本的路径中而不是在指定位置的头文件。 makefile中有一条注释,在LD_LIBRARY_PATH中包含opencv路径。我有Mac OS X 10.7.5并发现其等价物是DYLD_LIBRARY_PATH,但设置此环境变量并未更改编译器输出中的错误。我试图寻找解决方案,但没有找到任何解决方案。请帮我解决这个链接问题。提前谢谢。
这是安装opencv 3.0的地方:
/ Users / name / Desktop / opencv-master / release / opt / local /
以下是macports安装opencv 2.x的地方:
的/ opt /本地/
编译错误消息:(第一个错误发生在" /opt/local/include/opencv2/nonfree/features2d.hpp" ,其中表示一些链接问题。)
In file included from /Users/name/Desktop/opencv-master/release/opt/local/include/opencv2/core.hpp:52:0,
from /Users/name/Desktop/opencv-master/release/opt/local/include/opencv2/opencv.hpp:46,
from src/Evaluation.h:35,
from src/Evaluation.cpp:32:
/Users/name/Desktop/opencv-master/release/opt/local/include/opencv2/core/base.hpp:251:35: warning: unknown option after '#pragma GCC diagnostic' kind [-Wpragmas]
# pragma GCC diagnostic ignored "-Winvalid-noreturn"
^
In file included from /opt/local/include/opencv2/nonfree/nonfree.hpp:46:0,
from src/Evaluation.h:36,
from src/Evaluation.cpp:32:
/opt/local/include/opencv2/nonfree/features2d.hpp:73:21: error: 'vector' has not been declared
vector<KeyPoint>& keypoints) const;
^
/opt/local/include/opencv2/nonfree/features2d.hpp:73:27: error: expected ',' or '...' before '<' token
vector<KeyPoint>& keypoints) const;
^
/opt/local/include/opencv2/nonfree/features2d.hpp:77:21: error: 'vector' has not been declared
vector<KeyPoint>& keypoints,
^
/opt/local/include/opencv2/nonfree/features2d.hpp:77:27: error: expected ',' or '...' before '<' token
vector<KeyPoint>& keypoints,
^
/opt/local/include/opencv2/nonfree/features2d.hpp:76:10: error: 'void cv::SIFT::operator()(cv::InputArray, cv::InputArray, int) const' cannot be overloaded
void operator()(InputArray img, InputArray mask,
^
/opt/local/include/opencv2/nonfree/features2d.hpp:72:10: error: with 'void cv::SIFT::operator()(cv::InputArray, cv::InputArray, int) const'
void operator()(InputArray img, InputArray mask,
^
/opt/local/include/opencv2/nonfree/features2d.hpp:83:49: error: 'vector' has not been declared
void buildGaussianPyramid( const Mat& base, vector<Mat>& pyr, int nOctaves ) const;
^
/opt/local/include/opencv2/nonfree/features2d.hpp:83:55: error: expected ',' or '...' before '<' token
void buildGaussianPyramid( const Mat& base, vector<Mat>& pyr, int nOctaves ) const;
^
/opt/local/include/opencv2/nonfree/features2d.hpp:84:33: error: 'vector' does not name a type
void buildDoGPyramid( const vector<Mat>& pyr, vector<Mat>& dogpyr ) const;
^
/opt/local/include/opencv2/nonfree/features2d.hpp:84:39: error: expected ',' or '...' before '<' token
void buildDoGPyramid( const vector<Mat>& pyr, vector<Mat>& dogpyr ) const;
^
/opt/local/include/opencv2/nonfree/features2d.hpp:85:39: error: 'vector' does not name a type
void findScaleSpaceExtrema( const vector<Mat>& gauss_pyr, const vector<Mat>& dog_pyr,
^
/opt/local/include/opencv2/nonfree/features2d.hpp:85:45: error: expected ',' or '...' before '<' token
void findScaleSpaceExtrema( const vector<Mat>& gauss_pyr, const vector<Mat>& dog_pyr,
^
/opt/local/include/opencv2/nonfree/features2d.hpp:89:40: error: 'vector' has not been declared
void detectImpl( const Mat& image, vector<KeyPoint>& keypoints, const Mat& mask=Mat() ) const;
^
/opt/local/include/opencv2/nonfree/features2d.hpp:89:46: error: expected ',' or '...' before '<' token
void detectImpl( const Mat& image, vector<KeyPoint>& keypoints, const Mat& mask=Mat() ) const;
^
/opt/local/include/opencv2/nonfree/features2d.hpp:90:41: error: 'vector' has not been declared
void computeImpl( const Mat& image, vector<KeyPoint>& keypoints, Mat& descriptors ) const;
^
/opt/local/include/opencv2/nonfree/features2d.hpp:90:47: error: expected ',' or '...' before '<' token
void computeImpl( const Mat& image, vector<KeyPoint>& keypoints, Mat& descriptors ) const;
^
/opt/local/include/opencv2/nonfree/features2d.hpp:125:28: error: 'vector' has not been declared
CV_OUT vector<KeyPoint>& keypoints) const;
^
/opt/local/include/opencv2/nonfree/features2d.hpp:125:34: error: expected ',' or '...' before '<' token
CV_OUT vector<KeyPoint>& keypoints) const;
^
In file included from /opt/local/include/opencv2/nonfree/nonfree.hpp:46:0,
from src/Evaluation.h:36,
from src/Evaluation.cpp:32:
/opt/local/include/opencv2/nonfree/features2d.hpp:128:28: error: 'vector' has not been declared
CV_OUT vector<KeyPoint>& keypoints,
^
/opt/local/include/opencv2/nonfree/features2d.hpp:128:34: error: expected ',' or '...' before '<' token
CV_OUT vector<KeyPoint>& keypoints,
^
/opt/local/include/opencv2/nonfree/features2d.hpp:127:10: error: 'void cv::SURF::operator()(cv::InputArray, cv::InputArray, int) const' cannot be overloaded
void operator()(InputArray img, InputArray mask,
^
In file included from /opt/local/include/opencv2/nonfree/nonfree.hpp:46:0,
from src/Evaluation.h:36,
from src/Evaluation.cpp:32:
/opt/local/include/opencv2/nonfree/features2d.hpp:124:10: error: with 'void cv::SURF::operator()(cv::InputArray, cv::InputArray, int) const'
void operator()(InputArray img, InputArray mask,
^
In file included from /opt/local/include/opencv2/nonfree/nonfree.hpp:46:0,
from src/Evaluation.h:36,
from src/Evaluation.cpp:32:
/opt/local/include/opencv2/nonfree/features2d.hpp:142:40: error: 'vector' has not been declared
void detectImpl( const Mat& image, vector<KeyPoint>& keypoints, const Mat& mask=Mat() ) const;
^
/opt/local/include/opencv2/nonfree/features2d.hpp:142:46: error: expected ',' or '...' before '<' token
void detectImpl( const Mat& image, vector<KeyPoint>& keypoints, const Mat& mask=Mat() ) const;
^
/opt/local/include/opencv2/nonfree/features2d.hpp:143:41: error: 'vector' has not been declared
void computeImpl( const Mat& image, vector<KeyPoint>& keypoints, Mat& descriptors ) const;
^
/opt/local/include/opencv2/nonfree/features2d.hpp:143:47: error: expected ',' or '...' before '<' token
void computeImpl( const Mat& image, vector<KeyPoint>& keypoints, Mat& descriptors ) const;
^
Makefile内容:(我在这里更改了opencv路径变量,并添加了更多包含和库路径)
CC = g++
CFLAGS = -c
PFLAGS = -fopenmp
WFLAGS = -Wall -Warray-bounds
NFLAGS = -std=gnu++11
OPTS = -O1
OFLAGS = -g
#LFLAGS = -Lgui -lcpptk -ltcl8.5 -ltk8.5
#LFLAGS = -llapack -lm
LFLAGS = -llapack
# ENTER YOUR EXECUTABLE NAME HERE
EXECUTABLE = someName
#Opencv Includes Go here
####Change the OPENCV_PATH here#####
OPENCV_PATH= /Users/name/Desktop/opencv-master/release/opt/local
OPENCV_LIBS = -lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_objdetect -lopencv_ts -lopencv_video -lopencv_nonfree -lopencv_videostab
#OPENCV_LIBS = -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_highgui -lopencv_imgproc -lopencv_video
OPENCV_INCPATH = -I$(OPENCV_PATH)/include
OPENCV_INCPATH1 = -I$(OPENCV_PATH)/include/opencv
OPENCV_INCPATH2 = -I$(OPENCV_PATH)/include/opencv2
#/opencv2/ -I$(OPENCV_PATH)/include/opencv/
OPENCV_LIBPATH = -L$(OPENCV_PATH)/lib
OPENCV_LIBPATH2 = -L$(OPENCV_PATH)
OPENCV_LIBPATH3 = -L$(OPENCV_PATH)/include/opencv
OPENCV_LIBPATH4 = -L$(OPENCV_PATH)/include/opencv2
#Boost Libs Go Here
BOOST_LIBS = -lboost_system -lboost_filesystem -lboost_program_options
CPP_FILES := $(wildcard src/*.cpp)
OBJ_FILES := $(addprefix obj/,$(notdir $(CPP_FILES:.cpp=.o)))
SUBMIT_DIR = $(shell whoami)
BACKUP_DIR = $(shell date "+%b_%d_%Y_%I_%M")
BACKUP_REPO = ./Backups
BACKUP_PATH = $(BACKUP_REPO)/$(BACKUP_DIR)
all: $(EXECUTABLE)
$(EXECUTABLE): $(OBJ_FILES)
$(CC) $(NFLAGS) $(PFLAGS) $(WFLAGS) $(OPTS) $(LFLAGS) $(OPENCV_LIBS) $(OPENCV_INCPATH) $(OPENCV_INCPATH1) $(OPENCV_INCPATH2) $(OPENCV_LIBPATH) $(OPENCV_LIBPATH2) $(OPENCV_LIBPATH3) $(OPENCV_LIBPATH4) $(BOOST_LIBS) $^ -o $@ $(LFLAGS)
obj/%.o: src/%.cpp
mkdir -p ./obj
$(CC) $(NFLAGS) $(PFLAGS) $(CFLAGS) $(WFLAGS) $(OPTS) $(OFLAGS) $(OPENCV_LIBS) $(OPENCV_INCPATH) $(OPENCV_INCPATH1) $(OPENCV_INCPATH2) $(OPENCV_LIBPATH) $(OPENCV_LIBPATH2) $(OPENCV_LIBPATH3) $(OPENCV_LIBPATH4) $(BOOST_LIBS) -c -o $@ $< $(LFLAGS)
clean:
rm -f $(OBJ_FILES)
rm -f *.out
rm -f *~
rm -f $(EXECUTABLE)
#Create a Backup directory with <Month>_<Date>_<Year>_<Hr>_<Min>_<Sec>.tar
backup:
mkdir -p $(BACKUP_REPO)
mkdir -p $(BACKUP_PATH)
mkdir -p $(BACKUP_PATH)/src
cp -r ./src/*.h ./$(BACKUP_PATH)/src
cp -r ./src/*.cpp ./$(BACKUP_PATH)/src
cp Makefile $(BACKUP_PATH)/
#cp TestScript.sh $(BACKUP_PATH)/
tar -zcvf $(BACKUP_REPO)/$(BACKUP_DIR).tar $(BACKUP_PATH)/
rm -rf $(BACKUP_PATH)
我写道:
export DYLD_LIBRARY_PATH=/Users/name/Desktop/opencv-master/release/opt/local/lib
在 make 命令之前的终端中,但问题仍然存在。
感谢您的帮助。
答案 0 :(得分:1)
正如berak之前的评论所指出的,问题在于编译器。通过更改使用的编译器解决了此问题。这是通过编辑makefile来完成的:(CC = g ++ - mp-4.8)。
然后我在升级库文件方面遇到了一些错误,但是通过添加路径和附加&#34; -mt&#34;提升文件名,如(library not found for -lboost_system)中所述。
再次感谢,感谢您的帮助。