I want to create a program that can dlopen()create a series of libraries (written by me) and run all the functions stored in a global variable test_suiteinside this .so file, which is a NULL-complete array of function pointers (function signatures are predefined by itself, no need to worry about it )
The problem is that g ++ is modifying this variable. The library is compiled as:
g++ -Wall -shared -rdynamic -fPIC foo.cpp -o foo.so
and the "function index" is declared and distributed statically as:
const testunit_testcase test_suite = { ... }
till
objdump -t foo.so | grep test_suite
shows:
0000000000200940 l O .data.rel.ro 0000000000000020 _ZL10test_suite
I need
0000000000200940 l O .data.rel.ro 0000000000000020 test_suite
Therefore I can dlsym(dlh, "test_suite")in the program dlopen()'ingfoo.so
thank
Adding
Yes, extern "C"was the first thing I tried:
extern "C" {
const testunit_testcase test_suite[] = {
{NULL, NULL},
};
}
I use:
g++ -v . COLLECT_GCC = g++ COLLECT_LTO_WRAPPER =/USR/Library/GCC/x86_64--Linux-/4.5.2/LTO- : x86_64-unknown-linux-gnu : /build/src/ gcc-4.5-20110127/configure --prefix =/usr --enable-languages = c, ++, fortran, objc, obj-++, ada --enable-shared --enable-threads = posix --enable -__ cxa_atexit --enable-clocale = gnu --enable-gnu-unique-object --enable-lto --enable-plugin --enable-gold - -plugin-ld = ld.gold --disable-multilib --disable-libstdcxx-pch --with-system-zlib --with-ppl --with-cloog --with-cloog-include =/usr/include/cloog-PPL --libdir =/usr/lib --libexecdir =/usr/lib --mandir =/usr/share/man --infodir =/usr/share/info : posix gcc 4.5.220110127 (preerelease) (GCC)
2
-
extern "C" {
const testunit_testcase test_suite = { ... }
}
, :
extern "C" const testunit_testcase test_suite = { ... }
. , extern "C" { ... } . - , , , test_suite , , 4.x( ) g++?