链接共享库的gcc没有文件? [英] Link shared library in gcc without file?

查看:105
本文介绍了链接共享库的gcc没有文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们说我有我的目标系统上的 x.so 库,我不能对我的开发系统。

Let's say I have a x.so library on my target system that I can't have on my development system.

我需要编译,用gcc,我的开发机器上的程序,使用 x.so 在目标机器上运行。

I need to compile, using gcc, a program on my development machine that runs on the target machine using that x.so.

有没有办法做到这一点?

Is there any way to do this?

推荐答案

是的。你不反对该库链接所有,而是打开它的dlopen():

Yes. You don't link against that library at all, but rather open it with dlopen():

void* dlhandle = dlopen("x.so", RTLD_LAZY);

从它使用dlsym()

和载荷符号:

and load symbols from it using dlsym():

some_func_pointer = dlsym(dlhandle, "function");

您可以再通过函数指针从你得到的dlsym调用函数()()。该类型的函数指针必须的过程符合您正在加载的功能。它不检查你。

You can then call function() through the function pointer you get from dlsym(). The type of the function pointer must of course match the function you're loading. It is not checked for you.

这篇关于链接共享库的gcc没有文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆