Question

I'm currently trying to make a program that uses openCV for taking a picture from a webcam and performing graphical operations to find an area in openCV and then passing it to a .c program which just sends the information to a server via port programming.

my problem is that even though I created a .h file for the functions I used in the openCV .cpp code and included it in my .c, there's still an error saying error: expected ‘)’ before ‘&’ token

here is my simpleIS.h:

int captureimg();
int backgroundsub();
void noisesuppression(Mat &ptr);
void simplegetarea(Mat &img);

extern int area1,area2,area3,area4;

any ideas?

No correct solution

OTHER TIPS

You're going to have to wrap the functions you need in other C++ functions, and have those functions have extern "C" linkage. You're also going to have to have C data structures that hold the stuff you will need to create the C++ classes. Call the wrapper functions from C.

E.g., if you have a cpp function like this:

int im_a_cxx_function(int , some_type, another_type &);

You make a wrapper function :

extern "C" int im_a_cxx_wrapper_function(int i, 
                                          struct some_C_type *st_C, 
                                          struct another_C_type *at_C)
{
    some_type st;
    another_type at;

    set_some_type(&st,  st_C);
    set_another_type(&at, at_C);

    return im_a_cxx_function(i, st, at);
}

Then, in the header for your wrapper functions:

#ifdef __cplusplus
extern "C" {
#endif
int im_a_cxx_wrapper_function(int i, struct some_C_type *st_C, 
                               struct another_C_type *at_C);
#ifdef __cplusplus
}
#endif

Then, you include the header for your wrapper functions in your .c file, and call the the wrapper function normally. The main this is that you can't call a function without extern "C" from C due to name mangling, and since you aren't in control of the library functions, you have to wrap them up. You can also hold opaque pointers to C++ types, but since you can't use constructors, you'll generally have to at least write factory and delete functions for them.

Following shoud work. Your example.h file:

#pragma once

#ifdef __cplusplus
extern "C" {
#endif
    int __declspec(dllexport) main(int argc, char** argv); // just modify this line !!!
#ifdef __cplusplus
}
#endif

In your example.cpp file, change only:

extern "C" int main(int argc, char** argv)

You might want to modify function name for main() or change parameters.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top