c++ - Segmentation fault when calling c-function -


I have a static library (name it myStaticLib) which has c_mainwrapper. If I create a test-application, then I'll call the function MainControllerInitiate (); I can call without any problems.

When I create a shared library using my staticlib and c-scraper, I connect (); without any problems but when I try to call MainControllerInitiate (); I get a segmentation fault.

Files:
c_mainwrapper.h

  (. ..) typedef zero * MainController_p; Extern MainController_p (* createMainController) () #ifdef __cplusplus #define EXTERNC extern "C" # # externication #exfine #endif EXTERNC minus MainControllerInitiate (); (...) #undef EXTERNC (...)  

c_mainwrapper.cpp

  (...) MainController_p (* createMainController) () = Zero; (...) Zero MainControllerInitiate () {if (createMainController! = Null) {createMainController (); }} (...)  

c_wrapper.h

  (...) #include & lt; C_mainwrapper.h & gt; #ifdef __cplusplus #define EXTERNC extern "C" # # exterior EXTERNC #endif uninterrupted connect connect (); (...) #undef EXTERNC (...)  

c_wrapper.cpp

  (...) MainController_p createController () {New MainController back (); } Connect zero () {createMainController = & amp; CreateController; } (...)  

Edit:
Failed test-test is just:

  #include & lt; C_wrapper & gt; Int main (int argc, char * argv []) {connectCreate (); MainControllerInitiate (); // Segmentation error occurs here 0; }  

Edit 2: Unavailable createMainController = NULL added

Problem found by Myselfe:

Asked for any project files (tag Qt) I compiled the static library as debug and release and I wrote in the shared library project file:

< Pre> CONFIG (release: debug | release) {unix:! Macx: LIBS + = -L ../../ Build_Directory / x86 / Release / MyStatilib \ -lmyStaticLib} CONFIG (debug: debug | release) {UNIX:! Macx: LIBS + = -L ../../ BuildDirectory / x86 / Debug / Mystatic Lib \ -lmyStaticLib}

The problem is, I have used the wrong syntax I

  should be CONFIG (release, debug | release) { 

and not

  CONFIG (release: debug | release) {  

So I shared the shared library with the release version of the stable library. The error in the shared library was forced by itself. But I thought I would use the debug-version of the stable library and can move through the code for error.

Conclusion: The link against the library debug version if you want to step through the library code make-file


Comments