有没有办法通过名称获取外部变量(或函数)

发布于 2024-09-16 08:42:20 字数 97 浏览 2 评论 0原文

我想我最近读到了一个 C 标准库函数,它能够返回一个指向任何外部变量的指针,该变量的名称作为 const char * 传递给它。我认为它可以通过链接器符号起作用,如果有帮助的话。

I thought I read about a C standard library function recently that was able to return a pointer to any extern variable whose name was passed to it as a const char *. I think that it works via linker symbols, if that helps.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

那片花海 2024-09-23 08:42:20

您可能会想到 dlsym,它不是 C 标准库的一部分,而是 POSIX API 的一部分。

You could be thinking of dlsym, which is not part of the C standard library but part of the POSIX API.

贵在坚持 2024-09-23 08:42:20

这取决于系统。 dlsym 已经提到过。其 Windows 对应项是 GetProcAddress< /a>.在后一种情况下,该函数不仅需要是外部的,而且还需要导出。

It depends on the system. dlsym has already been mentioned. Its Windows counterpart is GetProcAddress. In the latter case, the function needs to be not only external but exported.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文