How do i create a .so file that contains only C++ code wrapped in C code - OpenCV related [closed]

asked 2013-11-14 19:01:50 -0600

joeish80829 gravatar image

updated 2013-11-14 19:52:06 -0600

On Ubuntu Saucy 64bit in termial using g++ Im attempting to wrap OpenCV in a language without a strong C++ ffi so im attempting to use C++ to C wrappers to aid in doing this... Here is the small peice of the files Im trying to convert just to get a feel for it(opencv_generated.hpp and opencv_generated.cpp at this link https://github.com/arjuncomar/opencv-raw)

opencv_generated hpp:

#include "cxcore.h"
#include "cv.h"
#include <opencv2/core/core.hpp>

#include <opencv2/opencv.hpp>
#include <vector>
#ifndef __OPENCV_GENERATED_HPP
#define __OPENCV_GENERATED_HPP
using namespace cv;
using namespace std;
using namespace flann;
using namespace cvflann;
extern "C" {
Mat* cv_imread(String* filename, int flags);
void cv_imshow(String* winname, Mat* mat);
bool cv_imwrite(String* filename, Mat* img, vector_int* params);}

opencv_generated.cpp:

#include "opencv_generated.hpp"
using namespace cv;
using namespace std;
using namespace flann;
using namespace cvflann;
extern "C" {

Mat* cv_imread(String* filename, int flags) {
return new Mat(cv::imread(*filename, flags));
}
void cv_imshow(String* winname, Mat* mat) {
    cv::imshow(*winname, *mat);
}
bool cv_imwrite(String* filename, Mat* img, vector_int* params) {
    return cv::imwrite(*filename, *img, *params);
}}

Am new to C wrappers for C++ and am trying to compile with

g++ -Wall -dynamiclib -I/home/w/test/opencv_generated.hpp -I/home/w/test/opencv_generated.cpp -o test.so

im getting error:

g++: fatal error: no input files

...im in the directory my opencv_generated.cpp and opencv_generated.hpp files are in so what am i doing wrong??....any help == greatly valued=)

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by sturkmen
close date 2020-10-11 04:01:47.795585

Comments

1

hey, man , the -I in the gcc cmdline is to include header dirs, not src files. so :

g++ -Wall -dynamiclib /home/w/test/opencv_generated.cpp -I/home/w/test -o test.so

actually , your code there is still c++. you probably need c++ on the inside of the wrappers, but c on the outside ( the interface ) so, you can't have any String or Mat types in your signature. (no use trying pointers, you need to wrap, what it points to!)

void* cv_imread( const char* filename, int flags) {
    return new Mat(cv::imread(filename, flags));
}
void cv_imshow( const char *winname, void* mat) {
    cv::imshow(winname, (*(Mat*)mat));
}
berak gravatar imageberak ( 2013-11-15 06:23:37 -0600 )edit