dlsym 命令可以从 .h 文件生成吗?

Can dlsym commands be generated from a .h file?

本文关键字:文件 命令 dlsym      更新时间:2023-10-16

已经解决了! 在此处查看结果。

不确定我是否在正确的地方询问,但是有谁知道基于 .h 文件生成 dlopen 和 dlsym 命令的正确方法?

我正在尝试动态加载 SDL2 - 这是一个用 C 编写的库 - 但所有提取函数列表及其带有 ctag 的参数的方法似乎都是徒劳的(必须手动更正 240 个函数中的 3500 个函数的参数列表并不好玩(。

ctags -R -x --sort=yes --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++ -f sdl /usr/include/SDL2/

ctags 的结果如下所示:

extern DECLSPEC int SDLCALL SDL_SetTextureColorMod (SDL_Texture * texture,
extern DECLSPEC int SDLCALL SDL_SetThreadPriority (SDL_ThreadPriority priority);
extern DECLSPEC void SDLCALL SDL_SetWindowBordered (SDL_Window * window,

这:

ctags -R -x --sort=yes --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++ -f sdl /usr/include/SDL2/ | grep "SDL_AddTimer"

产生这种结果:

SDL_AddTimer     prototype    93 /usr/include/SDL2/SDL_timer.h extern DECLSPEC SDL_TimerID SDLCALL SDL_AddTimer(Uint32 interval,

请注意间隔后缺少的参数。它坏了。

我也看到这是一件事情,它显然是自动生成的,而不是手工制作的。

那么......有谁知道有什么方法可以自动生成类似的东西?特别是对于 SDL2?

还是我应该只使用 SDL 函数,然后手动 dlsym?不要问为什么我不愿意只链接而不是使用 dlopen 和 dlsym。

我通过使用decltype解决了这个问题。

typedef decltype(SDL_RenderDrawRects)* PF_SDL_RenderDrawRects;

这样,我将不需要函数的参数列表。包装器可在此处找到。