lundi 2 mai 2016

I am trying to compile but I'm having a linking error

I'm trying to compile a program I wrote on a Mac 10.11 and my program is using an opencv library but I'm getting a linking error. Any help will be greatly appreciated:

undefined symbols for architecture x86_64:
  "begin_gui(cv::String)", referenced from:
      _main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [all] Error 1

I originally was able to compile and run my program using g++ -std=c++11 pig-config --cflags --libs opencv main.cpp.cpp -o mainbut that was when I had all my code inone file. I then split my program in multiple files so I can keep my code organized the following way

main.cpp:

#include "UI.h"

int main(int argc, char** argv){
    begin_gui(argv[1]);
    return 0;
}

UI.h:

#ifndef __U_I_INCLUDED__   
#define __U_I_INCLUDED__ 

#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/videoio/videoio.hpp"
#include "opencv2/highgui/highgui.hpp"

#include <iostream>
#include <tuple>

using namespace cv;
using namespace std;

int threshold_value=0;
int const threshold_type = 3;
int const max_value = 255;
int const max_BINARY_value = 255;
const char* windowname = "Remove Noise";
const char* trackbar_type = "Thresh Value";

Mat image_og, image_display, image_curr, image_tmp;
Mat section, thresh;
vector<Mat> history;
vector< tuple < Range,Range, int > > thresh_filters;
unsigned history_pointer=0;




Point left_down ;
Point left_up ;
Point high_light ;

void highlight(Point initial, Point end);

void myImshow(Mat left_image);

static void onMouse(int event, int x, int y, int flag, void*);

void undo();

void redo();

void myImshow(Mat input);

int begin_gui(String input);

#endif

UI.cpp:

#include "UI.h"




static void onMouse(int event, int x, int y, int flag, void*){

    #methods in here
    ...
}

void highlight(Point initial, Point end){

    #methods in here
    ...
}

void undo(){
    #methods in here
    ...

}
void redo(){

    #methods in here
    ...

}

void myImshow(Mat input){

    #methods in here
    ...

}

int begin_gui(String input){
    #methods in here
    ...
}

makefile:

CXX = g++
SOURCES = main.cpp #UI.cpp
OBJS = $(SOURCES:.cpp=.o)
INCLUDES = -I/usr/local/include/opencv
LINKS = 
OPENCV = `pkg-config opencv --cflags` `pkg-config opencv --libs`
CXXFLAGS = -std=c++11 \
            $(INCLUDES) \
            $(OPENCV)

LDFLAGS =

.o: %.cpp $(DEPS)
    $(CXX) $(CXXFLAGS) -o $@ -c $^

all: $(OBJS)
    $(CXX) $(CXXFLAGS) $(LDFLAGS) $(INCLUDES) -o out $(OBJS)

clean:
    rm -rf *.o

Aucun commentaire:

Enregistrer un commentaire