制作一个共享库

 /* 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. python中常用模块

    OS模块 python编程时,经常和文件.目录打交道,这是就离不了os模块.os模块包含普遍的操作系统功能,与具体的平台无关os.name()——判断现在正在实用的平台,Windows 返回 ‘nt' ...

  2. Statically Linking freeglut

    It’s possible statically link freeglut into your applications, instead of dynamically linking agains ...

  3. 开源录屏工具 Best Screen Recording Open Source Software For Windows 2017

    OBS Studio OBS (Open Broadcaster Software) - Free and open source software for live streaming and sc ...

  4. json-lib转化java对象,是否转化为null的属性

    public static void main(String[] args) throws Exception{ User user = new User(); user.setUid(25); Js ...

  5. poll & select

    //todo /* * copied from http://devarea.com/linux-io-multiplexing-select-vs-poll-vs-epoll/#.W1GZ0vkzZ ...

  6. Bootstrap -- 模态框实现拖拽移动

    ### 这里实现这个效果 需要引入 jquery-ui.min.js类库 jquery-ui.min.css样式 使用它提供的draggable()方法实现 ### 菜鸟教程 http://www.r ...

  7. docker的安装及项目部署

    Making Docker and Deployment Process Step: set up your docker environment build a image of activeMQ ...

  8. C# 使用EPPlus 秒导出10万条数据

    1.先要引用dll文件,可以直接使用vs自带的包管理,如下图: 输入 EPPlus 我这里是安装过了的所以这里显示的是卸载而不是安装. 安装成功了之后会看到这个dll文件 代码如下: //导出Exce ...

  9. Android 通过Intent调用系统功能和Action动作和服务广播【大全】

    1.从google搜索内容 Intent intent = new Intent(); intent.setAction(Intent.ACTION_WEB_SEARCH);intent.putExt ...

  10. Nginx(./configure --help)

    # ./configure --help --help print this message --prefix=PATH set installation prefix --sbin-path=PAT ...