c++11 - C++ constructs (vectors etc.) in a C++ static library, causing exception when run with a C code -


i've c++ static library exposes c++ apis & c++ library internally uses c++ constructs std::vectors etc.

api

classname::api1(int s, std::vector<enumcolors> vec); 

it's implementation in c++

class classname { public: std::vector<enumcolors> m_vec;     api1(int s, std::vector<enumcolors> vec)    {       m_vec = vec; // causing exception while running c code thru c wrapper    }  } 

now want use api in c code. hence, came c wrapper.

#ifdef __cplusplus extern "c" { #endif     typedef struct classname classname_c;     classname* createnew_c();     api1_c(classname_c* cpphandle, int s, enumcolors vec[], size_t      vecsize); #ifdef __cplusplus } #endif 

implementation of c wrapper

void api1_c(classname_c* cpphandle, int s, int vec[], size_t vecsize) {      std::vector<enumcolors> vecofenums;     //convert array vector     (size_t = 0; < vecsize; ++i)     {         vecofenums.push_back((enumcolors)vecofenums[i]);     }     cpphandle->api(s,vecofenums()); // call c++ api c } 

c code statically links c++ lib & calls api

    int main()     {     int colors[] = {0,1};                classname*cpphandle = createnew_c();        void api1_c(cpphandle, 100, colors, 2);     }   } 

this c code compiles & links fine. when executing c code, see control enters c++ api through teh c wrapper successfully.

but , exception thrown in c++ api implementation when following line hit.

  m_vec = vec;  

this seems because, above line trying vector operation & might c doesn't support vectors. in c++ library i've compiled using c++ compiler, shouldn't work.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -