制作一个共享库

 /* 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. sqlite处理数据

    # coding: UTF-8 import platform from _utils.patrol2 import run_cmd, data_format, report_format impor ...

  2. nc 搭建环境流程及问题

    1 拷贝目录,包括eclipse及home两个文件夹 2 将jdk环境配置为home里的jdk,现在为1.5 3 在mde development 中设置数据库链接及应用服务及端口号 4 新建mde项 ...

  3. 020_nginx禁止ip默认参数是$remote_addr无法禁止真实ip的问题

    由于网站使用了cdn所以$remote_addr获取的ip是cdn的ip,我现在先禁止某些ip访问发现无法禁止cdn传递过来的客户端的ip也就是$http_x_forwarded_for这个参数.比如 ...

  4. $Django 路由层(有,无名分组、反向解析、总路由分发、名称空间、伪静态)

    1 简单配置 -第一个参数是正则表达式(如果要精准匹配:'^publish/$')  -第二个参数是视图函数(不要加括号)  -url(r'^admin/', admin.site.urls), 注: ...

  5. mysql的csv数据导入与导出

    # 需要station_realtime存在 load data infile 'd:/xxxx/station_realtime2013_01.csv' into table `station_re ...

  6. 转载:UML学习(四)-----状态图(silent)

    原文:http://www.cnblogs.com/silent2012/archive/2011/11/01/2178278.html 状态图主要用于描述对象具有的各种状态.状态之间的转换过程以及触 ...

  7. Tomcat 部署项目的三种方法(转)

    转自:https://www.cnblogs.com/ysocean/p/6893446.html#_label0 1.下载 Tomcat 服务器 ①.官网下载地址:http://tomcat.apa ...

  8. oracle里面用sql做报表并带小计合计常用到的函数

    1-- DECODE函数是Oracle PL/SQL是功能强大的函数之一,假设我们想给职员加工资,其标准是:工资在8000元以下的将加20%:工资在8000元以上的加15%,通常的做法是,先选出记录 ...

  9. 【数据库】MySQL的左连接、右连接和全连接的实现

    表student:+----+-----------+------+| id | name | age |+----+-----------+------+| 1 | Jim | 18 || 2 | ...

  10. leetcode(js)算法之914卡牌分组

    给定一副牌,每张牌上都写着一个整数. 此时,你需要选定一个数字 X,使我们可以将整副牌按下述规则分成 1 组或更多组: 每组都有 X 张牌. 组内所有的牌上都写着相同的整数. 仅当你可选的 X > ...