liuliu / ccv

C-based/Cached/Core Computer Vision Library, A Modern Computer Vision Library
http://libccv.org
Other
7.07k stars 1.71k forks source link

Undefined reference to ccv functions #227

Closed carlosost closed 3 years ago

carlosost commented 3 years ago

I am trying to compile a simple example using OpenCV and CCV, but no matter the changes I do at the Makefile, I get some undefined reference to ccv functions. I've tried also to build a libccv.so instead of a libccv.a, but I still get the same errors, like bellow. Any idea what I am doing wrong? Any suggestion?

/tmp/ccOtb2on.o: In function `main':
test.cpp:(.text+0x2b1): undefined reference to `ccv_dense_matrix_new(int, int, int, void*, unsigned long)'
test.cpp:(.text+0x2c4): undefined reference to `ccv_scd_classifier_cascade_read(char const*)'
test.cpp:(.text+0x30c): undefined reference to `ccv_scd_detect_objects(ccv_dense_matrix_t*, ccv_scd_classifier_cascade_t**, int, ccv_scd_param_t)'
test.cpp:(.text+0x4cd): undefined reference to `ccv_array_free(ccv_array_t*)'
test.cpp:(.text+0x4dc): undefined reference to `ccv_matrix_free(void*)'
collect2: error: ld returned 1 exit status
Makefile:8: recipe for target 'test' failed
make: *** [test] Error 1

The code is as simples as bellow:

#include <iostream>

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgcodecs/imgcodecs.hpp>
#include <opencv2/imgproc/imgproc.hpp>

#include <ccv.h>

int main(int argc, char* argv[])
{   
    try {
        std::cout << "Starting tests..." << std::endl;
        cv::Mat img = cv::imread(argv[1], cv::IMREAD_COLOR);
        cv::cvtColor(img, img, cv::COLOR_BGR2RGB);
        img.convertTo(img, CV_8UC3);
        int width = img.cols;
        int height = img.rows;
        std::vector<uchar> img_vec;
        if (img.isContinuous()) {
            img_vec.assign((uchar*)img.datastart, (uchar*)img.dataend);
        } else {
            for (int i = 0; i < height; ++i) {
                img_vec.insert(img_vec.end(), img.ptr<uchar>(i), img.ptr<uchar>(i)+width);
            }
        }

        ccv_dense_matrix_t* image = ccv_dense_matrix_new(
            width, height, CCV_32F, img_vec.data(), 0);
        ccv_scd_classifier_cascade_t* cascade = ccv_scd_classifier_cascade_read("face.sqlite3");
        ccv_array_t* seq = ccv_scd_detect_objects(image, &cascade, 1, ccv_scd_default_params);
        if (seq->rnum == 0) {
            // exception face not found
            std::cout << "No face detected." << std::endl;
        } else {
            ccv_comp_t* comp = (ccv_comp_t*)ccv_array_get(seq, 0);
        }
        ccv_array_free(seq);
        ccv_matrix_free(image);   
    }
    catch (std::exception& ex) {
        std::cout << "Exception: " << std::string(ex.what()) << std::endl;
    } 
    return 0;
}

and the makefile is like:

OPEN_LIB = /opt/intel/openvino_2020.3.194/opencv/lib
OPEN_INC = /opt/intel/openvino_2020.3.194/opencv/include
CCV_INC = /home/carlosost/dev/3rdparty/ccv/lib

all: test

test: test.cpp
        g++ -Wall -pedantic -std=c++14 \
        -I${OPEN_INC} -I${CCV_INC} \
        test.cpp -o build/test \
        -L${OPEN_LIB} -L${CCV_INC} \
        -lccv -lpng -lopencv_core -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc 
clean:
        -rm -f build/test
liuliu commented 3 years ago

ccv is a C library. Your C++ code need to be modified for the include clause like this:

extern "C" {
#include <ccv.h>
}