參考資訊:
https://gcc.gnu.org/wiki/Visibility
main.c
#include <stdio.h>
void test(void);
int main(int argc, char *argv[])
{
test();
return 0;
}
test.c
#include <stdio.h>
void test(void)
{
}
編譯
$ gcc test.c -fPIC -shared -o test.so -fvisibility=hidden
$ gcc main.c test.so
/usr/bin/ld: /tmp/cctmpXxQ.o: in function `main':
main.c:(.text+0x10): undefined reference to `test'
collect2: error: ld returned 1 exit status
$ gcc test.c -fPIC -shared -o test.so -fvisibility=default
$ gcc main.c test.so
P.S. -fvisibility用來決定是否隱藏Shared Library的Symbol