Note that there are some explanatory texts on larger screens.

plurals
  1. POVariable dissapears in binary which is available in static lib
    primarykey
    data
    text
    <p>I have the problem mentioned. I create an object inside a static lib, it is there when I run <code>nm</code> on the static lib, but when i link the lib to a binary and run <code>nm</code> it has disappeared. I know this problem has been asked before, but I could not find any answers. It is important for me to be able to retain that variable in the binary because we are trying to implement version checks for static libs in a binary. Please help. Thank you. Example code follows:</p> <p><strong><em>test.h</em></strong></p> <pre><code>#ifndef TEST_H #define TEST_H class Test { public: Test(); }; extern Test* gpTest; #endif </code></pre> <p><strong><em>test.cpp</em></strong></p> <pre><code>#include "test.h" Test::Test() { gpTest = this; } Test test; </code></pre> <p><strong><em>main.cpp</em></strong></p> <pre><code>#include "test.h" #include &lt;iostream&gt; using namespace std; Test* gpTest = NULL; int main() { return 0; } </code></pre> <p><strong>BUILD</strong></p> <pre><code>g++ -c test.cpp -o test.o ar cr test.a test.o g++ main.cpp -o app -L/home/duminda/intest/test.a </code></pre> <p><strong><em>nm -C test.a</em></strong></p> <pre><code>0000000000000054 t global constructors keyed to _ZN4TestC2Ev 000000000000002b t __static_initialization_and_destruction_0(int, int) 0000000000000016 T Test::Test() 0000000000000000 T Test::Test() U __gxx_personality_v0 U gpTest 0000000000000000 B test </code></pre> <p><strong><em>nm -C app</em></strong></p> <pre><code>0000000000600e10 d _DYNAMIC 0000000000600fe8 d _GLOBAL_OFFSET_TABLE_ 0000000000400754 t global constructors keyed to gpTest 0000000000400858 R _IO_stdin_used w _Jv_RegisterClasses 0000000000400717 t __static_initialization_and_destruction_0(int, int) U std::ios_base::Init::Init()@@GLIBCXX_3.4 U std::ios_base::Init::~Init()@@GLIBCXX_3.4 0000000000601050 b std::__ioinit 0000000000600df0 d __CTOR_END__ 0000000000600de0 d __CTOR_LIST__ 0000000000600e00 D __DTOR_END__ 0000000000600df8 d __DTOR_LIST__ 0000000000400968 r __FRAME_END__ 0000000000600e08 d __JCR_END__ 0000000000600e08 d __JCR_LIST__ 0000000000601038 A __bss_start U __cxa_atexit@@GLIBC_2.2.5 0000000000601028 D __data_start 0000000000400810 t __do_global_ctors_aux 0000000000400670 t __do_global_dtors_aux 0000000000601030 D __dso_handle w __gmon_start__ U __gxx_personality_v0@@CXXABI_1.3 0000000000600ddc d __init_array_end 0000000000600ddc d __init_array_start 0000000000400770 T __libc_csu_fini 0000000000400780 T __libc_csu_init U __libc_start_main@@GLIBC_2.2.5 0000000000601038 A _edata 0000000000601058 A _end 0000000000400848 T _fini 00000000004005a0 T _init 0000000000400620 T _start 000000000040064c t call_gmon_start 0000000000601038 b completed.6096 0000000000601028 W data_start 0000000000601040 b dtor_idx.6098 00000000004006e0 t frame_dummy 0000000000601048 B gpTest 000000000040070c T main </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload