SylixOS动态库的初始化和清理

gewenbin
gewenbin
gewenbin
188
文章
15
评论
2020年12月23日20:44:51 评论 598

参考以下博客:

https://blog.csdn.net/xy010902100449/article/details/47263049

https://blog.csdn.net/lixiangminghate/article/details/44300839

1. 动态库示例代码

#include <SylixOS.h>

void __attribute__((constructor)) brfore_main(void); //在main函数之前被调用
void after_main (void);

void brfore_main (void)
{
    printf("brfore_main call!\n");

    atexit((void (*)(void)) after_main); //注册程序结束时调用的函数
}

void lib_func (void)
{
    printf("lib_func call!\n");
}

void after_main (void)
{
    printf("after_main call!\n");
}

2. 测试程序示例代码

#include <stdio.h>

void lib_func (void);

int main (int argc, char **argv)
{
    printf("Hello SylixOS!\n");

    lib_func();

    return  (0);
}

3. 运行结果

[root@sylixos:/root]# cd /apps/test/
[root@sylixos:/apps/test]# ./test
brfore_main call!
Hello SylixOS!
lib_func call!
after_main call!
[root@sylixos:/apps/test]#
gewenbin
  • 本文由 发表于 2020年12月23日20:44:51
  • 转载请务必保留本文链接:http://www.databusworld.cn/9697.html
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: