0

I am using a make file to compile a c++ opencv 2.4.3 program here is my code.

#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;
}

makefile

# 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)

Here is How I compile

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

I get the popular error:

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

I tried to fix it by googling but I couldn't. Any help?

Jeanne
  • 1,241
  • 3
  • 19
  • 28
  • The output you show is _clearly_ not coming from the makefile you've listed. Please don't paraphrase or modify things: how can we debug your problem? Show exactly what command you ran and what the output was, including the exact, complete error messages you get. – MadScientist May 15 '16 at 18:58
  • @MadScientist, I edit my question to put the full error message. – Jeanne May 15 '16 at 19:00
  • Possible duplicate of [OpenCV Undefined symbols for architecture x86\_64 after upgrading to OSX Maverick](http://stackoverflow.com/questions/19554621/opencv-undefined-symbols-for-architecture-x86-64-after-upgrading-to-osx-maverick) – Alex Cohn May 15 '16 at 19:03
  • @AlexCohn, I tried it but it does not fix the problem. – Jeanne May 15 '16 at 19:07
  • 1
    Are you on Linux or OSX? On OSX you'll probably do much better using `CC = clang++` rather than `g++` (note that `CC` is usually used for a C compiler; `CXX` is the standard variable name for the C++ compiler). – MadScientist May 15 '16 at 19:13
  • 1
    @MadScientist, thanks it works with clang++ – Jeanne May 15 '16 at 19:26

0 Answers0