MyExportFunctions.cpp,内容如下:| 1 2 3 4 5 6 | int Add(int a, int b) { return a + b; } int Sub(int a, int b) { return a - b; } |
| 1 | gcc -shared-o libExportFunctions.so MyExportFunctions.cpp |
nm -g命令看查看所有导出的函数,Add和Sub都已经导出了。| 1 2 3 4 5 6 7 8 9 10 11 12 13 | nm -g libExportFunctions.so 0000000000201028 B __bss_start w __cxa_finalize@@GLIBC_2.2.5 0000000000201028 D _edata 0000000000201030 B _end 00000000000006ac T _fini w __gmon_start__ 0000000000000550 T _init w _ITM_deregisterTMCloneTable w _ITM_registerTMCloneTable w _Jv_RegisterClasses 0000000000000680 T _Z3Addii 0000000000000694 T _Z3Subii |
| 1 2 3 4 5 6 7 8 | extern "C"{ int Add(int a, int b) { return a + b; } int Sub(int a, int b) { return a - b; } } |
| 1 2 3 4 5 6 7 8 9 10 11 12 13 | nm -g libExportFunctions.so 0000000000000670 T Add 0000000000201028 B __bss_start w __cxa_finalize@@GLIBC_2.2.5 0000000000201028 D _edata 0000000000201030 B _end 000000000000069c T _fini w __gmon_start__ 0000000000000540 T _init w _ITM_deregisterTMCloneTable w _ITM_registerTMCloneTable w _Jv_RegisterClasses 0000000000000684 T Sub |
| 1 2 3 4 5 6 7 8 | extern "C"{ __attribute__ ((visibility ("default")))int Add(int a, int b) { return a + b; } int Sub(int a, int b) { return a - b; } } |
-fvisibility=hidden| 1 | gcc -shared -fvisibility=hidden -o libExportFunctions.so MyExportFunctions.cpp |
| 1 2 3 4 5 6 7 8 9 10 11 12 | nm -g libExportFunctions.so 0000000000000660 T Add 0000000000201028 B __bss_start w __cxa_finalize@@GLIBC_2.2.5 0000000000201028 D _edata 0000000000201030 B _end 000000000000068c T _fini w __gmon_start__ 0000000000000528 T _init w _ITM_deregisterTMCloneTable w _ITM_registerTMCloneTable w _Jv_RegisterClasses |
| 1 2 3 4 | { global: Sub; local: *; }; |
| 1 | gcc -shared -Wl,--version-script=exportmap -o libExportFunctions.so MyExportFunctions.cpp |
nm -g查看,结果是| 1 2 3 4 5 6 7 | nm -g libExportFunctions.so w __cxa_finalize@@GLIBC_2.2.5 w __gmon_start__ w _ITM_deregisterTMCloneTable w _ITM_registerTMCloneTable w _Jv_RegisterClasses 00000000000005b4 T Sub |