带有makefile的体系结构x86_64的未定义符号

时间:2016-05-15 18:50:56

标签: opencv compilation makefile g++

我正在使用make文件来编译c ++ opencv 2.4.3程序,这是我的代码。

#include<iostream>
#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
using namespace cv;
using namespace std;
int main (int argc, char** argv)
{
    if(argc!=2)
    {
        cout<<" Usage: display_image ImageToLoad_Zoomed_and displayed "<<endl;
        return -1;
    }



Mat image;
image =imread(argv[1],CV_LOAD_IMAGE_GRAYSCALE );

if(!image.data)
{
    cout<< "Could not open or find the image"<<endl;
    return -1;
}

cout<<"Show Image"<<endl;
namedWindow("Display window", WINDOW_AUTOSIZE);
imshow("Display window ", image);
waitKey(0);
return 0;
}

生成文件

# compiler
CC :=g++
# include files
CFLAGS :=`pkg-config --cflags opencv`  
LDFLAGS :=`pkg-config --libs opencv`
# compile all c++ files in dir
SOURCES :=$(*.cpp)
# C++ files .cpp removed file is executable
EXECUTABLE :=$(SOURCES:.cpp=)

all:$(EXECUTABLE)

$(EXECUTABLE):$(SOURCES)
     $(CC) $< $(LDFLAGS) $(CFLAGS) -o $@

clean:
    rm -rf $(EXECUTABLE)

以下是我如何编译

g ++ display.cpp pkg-config opencv --cflags pkg-config opencv --libs -o display

我得到了流行的错误:

Undefined symbols for architecture x86_64:
  "cv::namedWindow(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)", referenced from:
      _main in ccAbu9Kb.o
  "cv::imread(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)", referenced from:
      _main in ccAbu9Kb.o
  "cv::imshow(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)", referenced from:
      _main in ccAbu9Kb.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status

我试图通过谷歌搜索解决它,但我无法解决。有什么帮助吗?

0 个答案:

没有答案