__ATTRIBUTE__ ((default)) and __attribute__ ((hidden))

Source: Internet
Author: User

Make a shared library

1 /*  */2int func ();
1 /*A.C*/2#include <stdio.h>3#include"a.h"4 5 intfunc ()6 {7printf"# # Func ###\n");8     return 0;9}
Gcc-shared-o liba.so A.c-fpic


Main.c

1 " a.h " 2 3 int Main () 4 {5    func (); 6     return 0 7 }
Gcc-o main main.c-la-l.-wl,-rpath=.

If you precede func with the

__ATTRIBUTE__ ((Visibility ("hidden")))

When compiling main, error:

/tmp/ccbxixwp.o:in function ' main':main.c: (. text+0x7): Undefined reference to ' func'  1 exit status


If you add-fvisibility=hidden when compiling a dynamic library , the symbols for the dynamic library are hidden

Add __attribute__ ((Visibility ("default")) before the function to make the function visible to the outside

__ATTRIBUTE__ ((default)) and __attribute__ ((hidden))

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.