C++: linked library disappears and gives segfault during execution

丶灬走出姿态 提交于 2020-01-03 03:25:52

问题


I'm having a problem building a library. In the Makefile I tell g++ that I need tclstub8.6 by putting -ltclstub8.6, and g++ takes it into account (sorry for these messages in French):

make: AVERTISSEMENT : le fichier « ../Linux-PORT/i586-GCC4/Makefile » a une date de modification 609 s dans le futur
*** Compile c [gcc] libtestGuiMnt_info.Linux-PORT.i586-GCC4.c
*** Compile C++ [g++] mntdisplay.cc
*** Compile C++ [g++] mntogl.cc
mntogl.cc: In member function 'virtual int MNTOgl::Display() const':
mntogl.cc:228:12: warning: unused variable 'ErrorCheckValue' [-Wunused-variable]
*** Compile C++ [g++] mntdisplaylist.cc
*** Compile C++ [g++] mntmanager.cc
*** Compile C++ [g++] mntdisplay_wrap.cc
*** Link (g++) librairie partagée /apollo/Developpement/Build-GCC4/Obj/Linux-PORT/i586-GCC4/lib/libtestGuiMnt.1 -Wl,-Bdynamic -L/apollo/Developpement/Build-GCC4/Obj/Linux-PORT/i586-GCC4/lib -Wl,-rpath,/apollo/Developpement/Build-GCC4/Obj/Linux-PORT/i586-GCC4/lib -lapcomutil -lapmntcom -lapmntdata -lapmntnoyau -lapcomenvEtude -lapcomenv -ltclstub8.6 -lGLEW -lGLU -lGL -lglut
make: AVERTISSEMENT : décalage d'horloge détecté. La construction peut être incomplète.

But when I call a tcl function, a segfault occurs.

In fact if I check the library I just built with ldd -r command, it shows that every external library is included, except tclstub8.6.

Below is the output messages of ldd -r command. Note that libtclstub8.6 does not appear..

And the list ends with all undefined symbols of libtclstub8.6.

ldd -r /apollo/Developpement/Build-GCC4/Obj/Linux-PORT/i586-GCC4/lib/libtestGuiMnt.1
        linux-gate.so.1 (0xb777e000)
        libapcomutil.2 => /apollo/Developpement/Build-GCC4/Obj/Linux-PORT/i586-GCC4/lib/libapcomutil.2 (0xb7743000)
        libapmntcom.1 => /apollo/Developpement/Build-GCC4/Obj/Linux-PORT/i586-GCC4/lib/libapmntcom.1 (0xb773f000)
        libapmntdata.3 => /apollo/Developpement/Build-GCC4/Obj/Linux-PORT/i586-GCC4/lib/libapmntdata.3 (0xb770f000)
        libapmntnoyau.4 => /apollo/Developpement/Build-GCC4/Obj/Linux-PORT/i586-GCC4/lib/libapmntnoyau.4 (0xb76e9000)
        libapcomenvEtude.1 => /apollo/Developpement/Build-GCC4/Obj/Linux-PORT/i586-GCC4/lib/libapcomenvEtude.1 (0xb76cc000)
        libapcomenv.1 => /apollo/Developpement/Build-GCC4/Obj/Linux-PORT/i586-GCC4/lib/libapcomenv.1 (0xb76b8000)
        libGLEW.so.1.9 => /usr/lib/libGLEW.so.1.9 (0xb762e000)
        libGLU.so.1 => /usr/lib/libGLU.so.1 (0xb75a6000)
        libGL.so.1 => /usr/lib/libGL.so.1 (0xb7546000)
        libglut.so.3 => /usr/lib/libglut.so.3 (0xb750a000)
        libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0xb741e000)
        libm.so.6 => /lib/libm.so.6 (0xb73dc000)
        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0xb73be000)
        libc.so.6 => /lib/libc.so.6 (0xb7244000)
        libapcomfichier.3 => /apollo/Developpement/Build-GCC4/Obj/Linux-PORT/i586-GCC4/lib/libapcomfichier.3 (0xb7235000)
        libapcomitineraire.3 => /apollo/Developpement/Build-GCC4/Obj/Linux-PORT/i586-GCC4/lib/libapcomitineraire.3 (0xb7190000)
        libxml2.so.2 => /usr/lib/libxml2.so.2 (0xb7036000)
        libz.so.1 => /lib/libz.so.1 (0xb701f000)
        libgfortran.so.3 => /usr/lib/libgfortran.so.3 (0xb6f22000)
        libglapi.so.0 => /usr/lib/libglapi.so.0 (0xb6f0c000)
        libXext.so.6 => /usr/lib/libXext.so.6 (0xb6ef9000)
        libXdamage.so.1 => /usr/lib/libXdamage.so.1 (0xb6ef5000)
        libXfixes.so.3 => /usr/lib/libXfixes.so.3 (0xb6eef000)
        libX11-xcb.so.1 => /usr/lib/libX11-xcb.so.1 (0xb6eeb000)
        libX11.so.6 => /usr/lib/libX11.so.6 (0xb6db1000)
        libxcb-glx.so.0 => /usr/lib/libxcb-glx.so.0 (0xb6d98000)
        libxcb.so.1 => /usr/lib/libxcb.so.1 (0xb6d75000)
        libXxf86vm.so.1 => /usr/lib/libXxf86vm.so.1 (0xb6d6f000)
        libdrm.so.2 => /usr/lib/libdrm.so.2 (0xb6d61000)
        libpthread.so.0 => /lib/libpthread.so.0 (0xb6d45000)
        libdl.so.2 => /lib/libdl.so.2 (0xb6d40000)
        libXi.so.6 => /usr/lib/libXi.so.6 (0xb6d30000)
        libXrandr.so.2 => /usr/lib/libXrandr.so.2 (0xb6d25000)
        /lib/ld-linux.so.2 (0xb777f000)
        liblzma.so.5 => /usr/lib/liblzma.so.5 (0xb6cfb000)
        libquadmath.so.0 => /usr/lib/libquadmath.so.0 (0xb6c82000)
        libXau.so.6 => /usr/lib/libXau.so.6 (0xb6c7e000)
        libXrender.so.1 => /usr/lib/libXrender.so.1 (0xb6c73000)
undefined symbol: Tcl_DeleteCommandFromToken    (/apollo/Developpement/Build-GCC4/Obj/Linux-PORT/i586-GCC4/lib/libtestGuiMnt.1)
undefined symbol: Tcl_NewStringObj      (/apollo/Developpement/Build-GCC4/Obj/Linux-PORT/i586-GCC4/lib/libtestGuiMnt.1)
undefined symbol: Tcl_GetCommandInfo    (/apollo/Developpement/Build-GCC4/Obj/Linux-PORT/i586-GCC4/lib/libtestGuiMnt.1)
undefined symbol: Tcl_SetObjResult      (/apollo/Developpement/Build-GCC4/Obj/Linux-PORT/i586-GCC4/lib/libtestGuiMnt.1)
undefined symbol: Tcl_GetLongFromObj    (/apollo/Developpement/Build-GCC4/Obj/Linux-PORT/i586-GCC4/lib/libtestGuiMnt.1)
undefined symbol: Tcl_InitHashTable     (/apollo/Developpement/Build-GCC4/Obj/Linux-PORT/i586-GCC4/lib/libtestGuiMnt.1)
undefined symbol: Tcl_CreateObjCommand  (/apollo/Developpement/Build-GCC4/Obj/Linux-PORT/i586-GCC4/lib/libtestGuiMnt.1)
undefined symbol: Tcl_NewBooleanObj     (/apollo/Developpement/Build-GCC4/Obj/Linux-PORT/i586-GCC4/lib/libtestGuiMnt.1)
undefined symbol: Tcl_SetResult (/apollo/Developpement/Build-GCC4/Obj/Linux-PORT/i586-GCC4/lib/libtestGuiMnt.1)
undefined symbol: Tcl_GetStringResult   (/apollo/Developpement/Build-GCC4/Obj/Linux-PORT/i586-GCC4/lib/libtestGuiMnt.1)
undefined symbol: Tcl_SetVar    (/apollo/Developpement/Build-GCC4/Obj/Linux-PORT/i586-GCC4/lib/libtestGuiMnt.1)
undefined symbol: Tcl_VarEval   (/apollo/Developpement/Build-GCC4/Obj/Linux-PORT/i586-GCC4/lib/libtestGuiMnt.1)
undefined symbol: Tcl_GetVar    (/apollo/Developpement/Build-GCC4/Obj/Linux-PORT/i586-GCC4/lib/libtestGuiMnt.1)
undefined symbol: Tcl_AppendResult      (/apollo/Developpement/Build-GCC4/Obj/Linux-PORT/i586-GCC4/lib/libtestGuiMnt.1)
undefined symbol: Tcl_AppendElement     (/apollo/Developpement/Build-GCC4/Obj/Linux-PORT/i586-GCC4/lib/libtestGuiMnt.1)
undefined symbol: Tcl_ObjSetVar2        (/apollo/Developpement/Build-GCC4/Obj/Linux-PORT/i586-GCC4/lib/libtestGuiMnt.1)
undefined symbol: Tcl_ResetResult       (/apollo/Developpement/Build-GCC4/Obj/Linux-PORT/i586-GCC4/lib/libtestGuiMnt.1)
undefined symbol: Tcl_SetErrorCode      (/apollo/Developpement/Build-GCC4/Obj/Linux-PORT/i586-GCC4/lib/libtestGuiMnt.1)
undefined symbol: Tcl_PkgProvide        (/apollo/Developpement/Build-GCC4/Obj/Linux-PORT/i586-GCC4/lib/libtestGuiMnt.1)
undefined symbol: _ZN10MNTManager10DisplayAllEv (/apollo/Developpement/Build-GCC4/Obj/Linux-PORT/i586-GCC4/lib/libtestGuiMnt.1)
undefined symbol: Tcl_GetStringFromObj  (/apollo/Developpement/Build-GCC4/Obj/Linux-PORT/i586-GCC4/lib/libtestGuiMnt.1)
undefined symbol: Tcl_NewDoubleObj      (/apollo/Developpement/Build-GCC4/Obj/Linux-PORT/i586-GCC4/lib/libtestGuiMnt.1)
undefined symbol: Tcl_GetBooleanFromObj (/apollo/Developpement/Build-GCC4/Obj/Linux-PORT/i586-GCC4/lib/libtestGuiMnt.1)
undefined symbol: Tcl_GetObjResult      (/apollo/Developpement/Build-GCC4/Obj/Linux-PORT/i586-GCC4/lib/libtestGuiMnt.1)
undefined symbol: TclFreeObj    (/apollo/Developpement/Build-GCC4/Obj/Linux-PORT/i586-GCC4/lib/libtestGuiMnt.1)
undefined symbol: Tcl_GetDoubleFromObj  (/apollo/Developpement/Build-GCC4/Obj/Linux-PORT/i586-GCC4/lib/libtestGuiMnt.1)
undefined symbol: Tcl_DuplicateObj      (/apollo/Developpement/Build-GCC4/Obj/Linux-PORT/i586-GCC4/lib/libtestGuiMnt.1)
undefined symbol: Tcl_DeleteHashEntry   (/apollo/Developpement/Build-GCC4/Obj/Linux-PORT/i586-GCC4/lib/libtestGuiMnt.1)
undefined symbol: Tcl_NewIntObj (/apollo/Developpement/Build-GCC4/Obj/Linux-PORT/i586-GCC4/lib/libtestGuiMnt.1)

Could someone help me with this issue? Thank you very much!


回答1:


I found it.

In fact everything was because of this line:

undefined symbol: _ZN10MNTManager10DisplayAllEv (/apollo/Developpement/Build-GCC4/Obj/Linux-PORT/i586-GCC4/lib/libtestGuiMnt.1)

There is an undefined symbol of MY library. I defined it and problem solved!

Please see my original post: segfault using SWIG converted code for tcl

The confusion was, my program crashed in the middle of tcl wrapper functions (where my undefined symbol was not involved at all). I don't really know why but that's it..

Hope it will help others!



来源:https://stackoverflow.com/questions/18379452/c-linked-library-disappears-and-gives-segfault-during-execution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!