How do i create a .so file that contains only C++ code wrapped in C code - OpenCV related [closed]
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=)
hey, man , the -I in the gcc cmdline is to include header dirs, not src files. 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!)