I'm trying to use --version-script flag to hide a huge list of unwanted symbols to keep only the symbols that define the interface of my shared library. Here is the call to linker:
/usr/bin/cc -fPIC -Wl,--version-script=/home/bil/Documents/matlab/tolibrary/dll_c_rowmj_cont_nirall/dll/test.map -shared -Wl,-soname,libmatlab_lib.so -o libmatlab_lib.so CMakeFiles/matlab_lib.dir/any.c.o CMakeFiles/matlab_lib.dir/classificJob.c.o CMakeFiles/matlab_lib.dir/container.cpp.o CMakeFiles/matlab_lib.dir/container_helper_functions.c.o CMakeFiles/matlab_lib.dir/container_wrap.cpp.o CMakeFiles/matlab_lib.dir/decisionJob.c.o CMakeFiles/matlab_lib.dir/initJob.c.o CMakeFiles/matlab_lib.dir/mean.c.o CMakeFiles/matlab_lib.dir/nirJob.c.o CMakeFiles/matlab_lib.dir/nirJob_initialize.c.o CMakeFiles/matlab_lib.dir/nirJob_terminate.c.o CMakeFiles/matlab_lib.dir/rtGetInf.c.o CMakeFiles/matlab_lib.dir/rtGetNaN.c.o CMakeFiles/matlab_lib.dir/rt_nonfinite.c.o CMakeFiles/matlab_lib.dir/zscore.c.o -lstdc++ -lm
And here is the test.map file:
FOO {
global: container_to_string; nirJob; decisionJob; initJob; classificJob; # explicitly list symbols to be exported
local: *; # hide everything else
};
Here is the output of nm command on the .so
nm -D libmatlab_lib.so
U ceil
000000000000215f T classificJob
0000000000009fad T container_to_string
U __cxa_allocate_exception
U __cxa_atexit
U __cxa_begin_catch
U __cxa_end_catch
w __cxa_finalize
U __cxa_rethrow
U __cxa_throw
0000000000026cc5 T decisionJob
U floor
0000000000000000 A FOO
U fwrite
U get_double
w __gmon_start__
U __gxx_personality_v0
0000000000026d19 T initJob
w _ITM_deregisterTMCloneTable
w _ITM_registerTMCloneTable
U malloc
U memcmp
U memcpy
U memmove
U memset
0000000000026ec2 T nirJob
U sqrt
U __stack_chk_fail
U stderr
U strcpy
U _Unwind_Resume
U _ZdlPv
U _ZdlPvm
U _ZNKSt7__cxx1119basic_ostringstreamIcSt11char_traitsIcESaIcEE3strEv
U _ZNKSt8__detail20_Prime_rehash_policy14_M_need_rehashEmmm
U _ZNSaIcEC1ERKS_
U _ZNSaIcEC1Ev
U _ZNSaIcEC2ERKS_
U _ZNSaIcED1Ev
U _ZNSaIcED2Ev
U _ZNSolsEd
U _ZNSolsEf
U _ZNSolsEi
U _ZNSolsEj
U _ZNSolsEl
U _ZNSolsEm
U _ZNSolsEs
U _ZNSolsEt
U _ZNSt7__cxx1119basic_ostringstreamIcSt11char_traitsIcESaIcEEC1ESt13_Ios_Openmode
U _ZNSt7__cxx1119basic_ostringstreamIcSt11char_traitsIcESaIcEED1Ev
U _ZNSt8ios_base4InitC1Ev
U _ZNSt8ios_base4InitD1Ev
U _ZNSt9exceptionD2Ev
U _Znwm
U _ZSt11_Hash_bytesPKvmm
U _ZSt17__throw_bad_allocv
U _ZSt19__throw_logic_errorPKc
U _ZSt20__throw_length_errorPKc
U _ZSt4cout
U _ZStlsIcSt11char_traitsIcESaIcEERSt13basic_ostreamIT_T0_ES7_RKNSt7__cxx1112basic_stringIS4_S5_T1_EE
U _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_a
U _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_h
U _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
U _ZTISt9exception
U _ZTVN10__cxxabiv120__si_class_type_infoE
U _ZTVSt9exception
The symbols I want to export are there but there is some extra stuff that I can't get rid off. Is there a readon ld adds all those symbols? How can I get rid of them?
Thank you.