您的位置:首页 > 运维架构 > Linux

linux .so 文件中函数名称和程序中的函数名称相同

2014-02-21 17:07 337 查看
~/so_test $ cat testlib.h
#ifndef __LIB_TEST_H__
#define __LIB_TEST_H__

void libxx();

#endif


~/so_test $ cat testlib.c
#include <stdio.h>
#include <stdlib.h>

void libxx()
{
printf("come from libxx.so\n");
}


~/so_test $ cat main.c
#include "testlib.h"
#include <stdlib.h>
#include <stdio.h>
#if 0
void libxx()
{
printf("come from prg!\n");
}
#endif

int main(int argc, char *argv[])
{
libxx();
return 0;
}


~/so_test $ gcc -fpic -shared -o libtest.so testlib.c

~/so_test $ gcc -l/home/admin/so_test -o main.o -c main.c

~/so_test $ gcc -o main -L/home/admin/so_test main.o -ltest

如果程序中有 libxx 这个函数 运行的时候调用的是程序中的, 如果 程序中没有这个函数那么就调用库里面的
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: