dude
dude

Reputation: 31

Mac Library Linking

I am trying to compile a given program that uses opencv 3.0. I already had opencv 2.x installed through macports and have been using it with my codes without any problem. However, the given program requires opencv 3.0 so I had to install it myself in some different location since this version was not available through macports. I tried to compile the given program with the given makefile after editing the opencv path. The problem is that I get compile errors that appears to be linking problems as it looks at header files located in the path of the 2.x version installed by macports and not in the specified location. There was a comment in the makefile to include the opencv path in the LD_LIBRARY_PATH. I have Mac OS X 10.7.5 and found out that its equivalent is DYLD_LIBRARY_PATH, but setting this environment variable did not change the error in the compiler output. I tried to search for a solution but didn't find any. Please help me fix this linking problem. Thanks in advance.


Here is where opencv 3.0 is installed:

/Users/name/Desktop/opencv-master/release/opt/local/

Here is where opencv 2.x is installed by macports:

/opt/local/


Compile error message: (The first error was in "/opt/local/include/opencv2/nonfree/features2d.hpp", which indicates some linking problem.)

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 contents: (I changed the opencv path variable here, and added more include and library paths)

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)

I wrote:

export DYLD_LIBRARY_PATH=/Users/name/Desktop/opencv-master/release/opt/local/lib

in the terminal before the make command, but the problem still exists.


Thank you for your help.

Upvotes: 1

Views: 888

Answers (1)

dude
dude

Reputation: 31

As pointed out in the previous comments by berak, the problem was with the compiler. This problem was resolved by changing the used compiler. That was done by editing the makefile: (CC = g++-mp-4.8).

Then I got some errors regarding the boost library files, but that was fixed by adding its path and appending "-mt" to boost file names, as answered in (library not found for -lboost_system).

Thanks again, I appreciate your help.

Upvotes: 1

Related Questions