制作一个共享库

 /* a.h */
int func();
 /* a.c */
#include <stdio.h>
#include "a.h" int func()
{
printf("### func ###\n");
return ;
}
gcc -shared -o liba.so a.c -fPIC

main.c

 #include "a.h"

 int main()
{
func();
return
}
gcc -o main main.c -la -L. -Wl,-rpath=.

如果在 func 前面加上

__attribute__((visibility("hidden")))

在编译 main 时,报错:

/tmp/ccbxiXwp.o: In function `main':
main.c:(.text+0x7): undefined reference to `func'
collect2: error: ld returned exit status

如果在编译动态库时加上 -fvisibility=hidden,表示动态库的符号都是 hidden的

在函数前加上 __attribute__((visibility("default"))) 可以使函数对外可见

__attribute__ ((default)) 和 __attribute__ ((hidden))的更多相关文章

  1. GCC的__attribute__ ((constructor))和__attribute__ ((destructor))

    通过一个简单的例子介绍一下gcc的__attribute__ ((constructor))属性的作用.gcc允许为函数设置__attribute__ ((constructor))和__attrib ...

  2. Linux __attribute__(("hidden"))、default

    记录下: Linux下导出so库接口时在下面情况下无法导出(编译时增加了__attribute__(("hidden"))属性). void * __attribute__((&q ...

  3. [转]GCC系列: __attribute__((visibility("")))

    在 objc-api.h 里面有很多关于__attribute__ 的定义. 例如 #if !defined(OBJC_VISIBLE) # if TARGET_OS_WIN32 # if defin ...

  4. iOS宏和__attribute__

    本文目录 iOS宏的经典用法 Apple的习惯 __attribute__ iOS宏的经典用法 1.常量宏.表达式宏 #define kTabBarH (49.0f) #define kScreenH ...

  5. __attribute__

    转来的: http://www.cnblogs.com/astwish/p/3460618.html __attribute__ 你知多少? GNU C 的一大特色就是__attribute__ 机制 ...

  6. __attribute__ 你知多少?

    GNU C 的一大特色就是__attribute__ 机制.__attribute__ 可以设置函数属性(Function Attribute ).变量属性(Variable Attribute )和 ...

  7. __ATTRIBUTE__ 你知多少?【转】

    转自:http://www.cnblogs.com/astwish/p/3460618.html GNU C 的一大特色就是__attribute__ 机制.__attribute__ 可以设置函数属 ...

  8. __attribute__你知多少(转)

    转自:http://www.cnblogs.com/astwish/p/3460618.html GNU C 的一大特色就是__attribute__ 机制.__attribute__ 可以设置函数属 ...

  9. __ATTRIBUTE__ 知多少?

    GNU C 的一大特色就是__attribute__ 机制.__attribute__ 可以设置函数属性(Function Attribute ).变量属性(Variable Attribute )和 ...

随机推荐

  1. SharePoint 2016: 数据库正在兼容性范围内运行,建议进行升级

    问题描述: SharePoint 运行状况分析器提示: 中文:数据库正在兼容性范围内运行,建议进行升级. 英文:Database running in compatibility range and ...

  2. hibernate框架学习之多表查询helloworld

    package cn.itcast.h3.hql; import java.util.List; import org.hibernate.Query; import org.hibernate.Se ...

  3. 033_linux操作系统火焰图探测系统性能

    火焰图是定位疑难杂症的神器,比如 CPU 占用高.内存泄漏等问题.特别是 Lua 级别的火焰图,可以定位到函数和代码级别. 一.研究 https://moonbingbing.gitbooks.io/ ...

  4. bootstrap4简单使用和入门03-响应式布局

    响应式布局的原理 页面源码 <!DOCTYPE html> <html lang="en"> <head> <meta charset=& ...

  5. hue的历史查询记录querys乱码问题解决

    hue的历史查询记录querys乱码问题解决: master1中配置文件/home/hadoop/.versions/hue-3.10.0/desktop/conf/hue.ini 可以看到连接的是m ...

  6. Spring Boot (一): Spring Boot starter自定义

    前些日子在公司接触了spring boot和spring cloud,有感于其大大简化了spring的配置过程,十分方便使用者快速构建项目,而且拥有丰富的starter供开发者使用.但是由于其自动化配 ...

  7. 牛客网 python 求解立方根

    •计算一个数字的立方根,不使用库函数 详细描述: •接口说明 原型: public static double getCubeRoot(double input) 输入:double 待求解参数 返回 ...

  8. Struts2框架的概述及学习重点

    什么是Struts2的框架 * Struts2是Struts1的下一代产品,是在 struts1和WebWork的技术基础上进行了合并的全新的Struts 2框架. * 其全新的Struts 2的体系 ...

  9. Confluence 6 针对站点维护使用只读模式

    如果你需要对 Confluence 进行维护,但是 Confluence 还是在运行或者你计划将站点合并到一个新的站点,你可以将你的 Confluence 站点设置为只读模式来限制用户在你站点中可以使 ...

  10. http超文本协议

    当今web程序的开发技术真是百家争鸣,ASP.NET, PHP, JSP,Perl, AJAX 等等. 无论Web技术在未来如何发展,理解Web程序之间通信的基本协议相当重要, 因为它让我们理解了We ...